首页 文章

连接ms访问数据库时出现连接错误

提问于
浏览
2

我想在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.

你有什么建议,为什么会出现这个错误 . 如果没有注册,那么如何注册 .

提前致谢

2 回答

  • 0

    问题可能出在平台上 . 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
    
  • 2

    这可能是因为Windows用户的seucrity设置问题,检查路径上的权限等 .

相关问题