Question

I'm trying to connect to an external .sdf file using VB.NET in VS2012. I'm having issues working with the System.Data.SqlServerCE DLL.

When I don't Copy Local I get the error: Could not load file or assembly 'System.Data.SqlServerCe, Version=3.5.1.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.

If I do Copy Local I get: Could not load file or assembly 'System.Data.SqlServerCe, Version=3.5.1.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

I have SQL Server Compact version 4 installed, so I'm referencing the DLL in "C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v4.0\Private". I've tried adding this DLL from other locations and will get the "Found conflicts between different version of the same dependent assembly" warning. If I click on that it'll add the following to the app.config:

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="System.Data.SqlServerCe" publicKeyToken="89845DCD8080CC91" culture="neutral"/>
      <bindingRedirect oldVersion="0.0.0.0-4.0.0.1" newVersion="4.0.0.1"/>
    </dependentAssembly>
  </assemblyBinding>
</runtime>

Once that is added to app.config I get this error:

Unable to load the native components of SQL Server Compact corresponding to the ADO.NET provider of version 8876. Install the correct version of SQL Server Compact. Refer to KB article 974247 for more details.


One thing I noticed earlier was that System.Data.SqlServerCe was not in the C:\Windows\Microsoft.NET\assembly folder. I installed the DLL using gacutil.exe and changed the

<bindingRedirect oldVersion="0.0.0.0-4.0.0.1" newVersion="4.0.0.1"/>

in app.config to

<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0"/>

(4.0.0.0 is the version listed by the gacutil).

This got me past the assembly errors at least. :)

It's too soon to post an answer for myself, so I'll just leave this edit.

Was it helpful?

Solution

I manage to fixed the above issue by using C:\Program Files\Microsoft SQL Server Compact Edition\v4.0\Desktop\System.Data.SqlServerCe.dll. So the System.Data.SqlServerCe.dll in path C:\Program Files\Microsoft SQL Server Compact Edition\v4.0\Private doesn't work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top