2
votes

I want to connect the ms access database in c# through ado.net at windows server 2008 R2 standard.

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];

But it gives an error:

The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine.

Have you any suggestion and why this error is coming. If it is not registered then how to register this.

Thanks in advance

2

2 Answers

2
votes

The problem might be of the Platform. The Jet OLEDB only supports x86 (32 bit OS) and not x64 64 (bit). There is not a 64 bit version of jet that is why you get that error.

To force your app to use the 32 bit change the target cpu to x86 in the advanced compiler options in visual studio.

This similar question on MSDN may help.

Also try manually registering the DLL yourself. For your Jet 4.0 the path of dlls are:

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

register the dll by using regsvr32 like this on command prompt:

regsvr32 C:\WINNT\System32\Msjetoledb40.dll
0
votes

This could be because of a windows user seucrity setting issue,check the rights over the path etc.