我想通过windows server 2008 R2标准的ado.net连接c#中的ms访问数据库。
using System.Data.OleDb; OleDbConnection connectionAccess = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\testTable.mdb"); OleDbDataAdapter adapterAccess = new OleDbDataAdapter("Select * from test", connectionAccess); DataSet ds = new DataSet(); adapterAccess.Fill(ds); dataGridView1.DataSource = ds.Tables[0];
但是它给出了一个错误:
The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine.
您有任何建议以及为什么会出现此错误。 如果没有注册,那么如何注册。
提前致谢
答案 0 :(得分:2)
问题可能出在平台上。 Jet OLEDB仅支持x86(32位操作系统)而不支持x64 64(位)。没有64位版本的jet,这就是你得到这个错误的原因。
要强制您的应用使用32位,请在Visual Studio的高级编译器选项中将目标cpu更改为x86。
这similar question on MSDN可能会有所帮助。
也可以尝试自己手动注册DLL。 对于Jet 4.0,dll的路径是:
Microsoft Jet 4.0 OLE DB Provider Provider=Microsoft.Jet.OLEDB.4.0 C:\WINNT\System32\Msjetoledb40.dll C:\WINNT\System32\Msjet40.dll C:\WINNT\System32\Mswstr10.dll C:\WINNT\System32\Msjter40.dll C:\WINNT\System32\Msjint40.dll
在命令提示符下使用regsvr32
这样注册dll:
regsvr32 C:\WINNT\System32\Msjetoledb40.dll
答案 1 :(得分:0)
这可能是因为Windows用户安全设置问题,请检查路径上的权限等。