我有一个带有两个项目的Visual Studio 2008解决方案(一个Word-Template项目和一个用于测试的VB.Net控制台应用程序)。这两个项目都引用一个数据库项目,该项目打开了与MS-Access 2007数据库文件的连接,并引用了System.Data.OleDb。在数据库项目中,我有一个检索数据表的功能,如下所示
private class AdminDatabase
' stores the connection string which is set in the New() method
dim strAdminConnection as string
public sub New()
...
adminName = dlgopen.FileName
conAdminDB = New OleDbConnection
conAdminDB.ConnectionString = "Data Source='" + adminName + "';" + _
"Provider=Microsoft.ACE.OLEDB.12.0"
' store the connection string in strAdminConnection
strAdminConnection = conAdminDB.ConnectionString.ToString()
My.Settings.SetUserOverride("AdminConnectionString", strAdminConnection)
...
End Sub
' retrieves data from the database
Public Function getDataTable(ByVal sqlStatement As String) As DataTable
Dim ds As New DataSet
Dim dt As New DataTable
Dim da As New OleDbDataAdapter
Dim localCon As New OleDbConnection
localCon.ConnectionString = strAdminConnection
Using localCon
Dim command As OleDbCommand = localCon.CreateCommand()
command.CommandText = sqlStatement
localCon.Open()
da.SelectCommand = command
da.Fill(dt)
getDataTable = dt
End Using
End Function
End Class
当我从Word 2007 Template项目中调用此函数时,一切正常。没有错误。但是,当我从控制台应用程序运行它时,它将引发以下异常
ex = {“'Microsoft.ACE.OLEDB.12.0'提供程序未在本地计算机上注册。”}
这两个项目具有相同的参考,并且控制台应用程序在我第一次编写它(前一阵子)时就可以工作,但是现在它已经停止工作。我一定想念什么,但我不知道。有任何想法吗?