‘Microsoft.Jet.OLEDB.4.0’ not registered

Like many of you, I'm now running a 64-bit operating system (Windows Server 2008) for my development environment. Although it may seem outdated, Access still has some use to me (mainly because we use Microsoft's Web Application Stress Tool for load testing).

Just recently, I ran into an odd issue that I couldn't understand, so I put forth the power of Google to find my answer; specifically, the error appeared in the following code:

   1:  using(OleDbConnection connection = new OleDbConnection(ConnectionString))
   2:  using(OleDbCommand command = new OleDbCommand(CmdText, connection))
   3:  {
   4:      connection.Open();
   5:      ....
   6:      connection.Close();
   7:  }

 Whenever the connection to the database was opened, I would get the following InvalidOperationException:

InvalidOperationException_1

It turns out, the fix is very simple, you just need to know where to look!

The problem exists in the 64-bit environment. Specifically, Microsoft does not have (or at least doesn’t ship) a x64 ODBC driver. One configuration change will fix this problem instantly!

Simply change your Solution Platform from “Any CPU” to “x86” and you should be good to go!

CPU_configuration