Weird error with Microsoft.Jet.OLEDB.4.0
I've made a C# application that uses the following connection string to connect to a database:
DbConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DataBaseFileName + "; Jet OLEDB:Engine Type=5";
I assumed for what I read that since Windows 2000 the Jet 4.0 engine comes with Windows. My application has an error report functionality that let the user send me an error report that contains a little information about the error whenever the program crashes. All my database queries have try/catches that should have prevented the app from crashing, except when it connects to the database. Here's is the error report:
<Message>Retrieving the COM class factory for component with CLSID {2206CDB2-19C1-11D1-89E0-00C04FD7A829} failed due to the following error: 800700c1 is not a valid Win32 application. (Exception from HRESULT: 0x800700C1).</Message>
<StackTrace> at System.RuntimeTypeHandle.CreateInstance(RuntimeTyp开发者_StackOverflowe type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Data.OleDb.OleDbConnectionInternal.CreateInstanceDataLinks()
at System.Data.OleDb.OleDbConnectionInternal.GetObjectPool()
</StackTrace>
<TypeName>System.BadImageFormatException</TypeName>
The user didn't give any description about how the error occurred. My program doesn't check for anything at installation or when running to ensure the JET engine is installed or not corrupt. Could that be the problem? Was it a mistake to assume that Jet 4.0 would be installed if the Windows version is >= 2000?
Please any advice will help. I'm kinda desperate.
Are you running a 64 bit OS ?
If so, you should change the 'Platform target' of your .NET application to 'x86' instead of 'Any CPU'. (In Project Properties; tabpage 'Build').
精彩评论