Beruflich Dokumente
Kultur Dokumente
/w EPDw UKMTM5
.3 Save the table as AccessTable .4 Start Visual Studio (on 64 bit machine) and create a new C# console application and replace the code in the main method with this: static void Main(string[] args) { string directory = @"C:\Temp";
string file = "Access2007.accdb"; string sql = "SELECT ID, FirstName, LastName FROM AccessTable"; string cs = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}\{1};Persist Security Info=False;", directory, file); try { using(OleDbConnection connection = new OleDbConnection(cs)) { connection.Open(); using(OleDbCommand cmd = new OleDbCommand(sql, connection)) { OleDbDataReader rdr = cmd.ExecuteReader(); while(rdr.Read()) { Console.WriteLine("ID:{0}, FirstName: {1}, LastName: {2}", rdr[0], rdr[1], rdr[2]); } } connection.Close(); } } catch(Exception ex) { Console.WriteLine(ex); } } .5 Run it and you should get the exception above. So what is going on? Well, there is currently no 64bit version of the Access driver, only a 32bit version. To make a long story short, by default your .Net project will be compiled with the anycpu platform switch. This means that when Windows have examined the .exe header it will (on a 64 bit machine) decide that this is a 64bit process. Of course, if you were running on a 32bit machine, Windows would decide that this is a 32 bit process. But when running as a 64bit process, the 32bit driver will not be found. So, since there is no 64 bit version of the Access driver, we need to run the .exe as a 32 bit (Wow64 application) process on the 64 bit machine. This is easy to do. .1 Right click your project and select Properties. .2 Select Build and select x86 in the Platform Target dropdown. .3 Save, Rebuild and run you project, you should now get the rows for the table. "C# Language Reference - /platform (Specify Output Platform) (C# Compiler Options)" http://msdn.microsoft.com/en-us/library/zekwfyz4.aspx