我有一个Visual Studio 2008方案,包含两个项目(一个Word模板项目和一个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模板项目中调用此函数时,一切正常;没有错误。但是当我从控制台应用程序运行它时,它会抛出以下异常。
ex = {"The Microsoft.ACE.OLEDB.12.0 provider is not registered on the local machine."}
这两个项目具有相同的参考文献,当我第一次编写控制台应用程序时它是工作的(一段时间以前),但现在它已经停止工作。我一定是遗漏了什么,但我不知道是什么。 有什么建议吗?