I’ve got an app that uses Sql CE 3.5 SP2. I’ve included the DLL’s that Sql CE requires – there are 7 of them found here (C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v3.5) that I simply add to my deployment package as application files.
I also use the EF to access the DB, so I’ve added an entry to my app.config file to provide a Data Provider:
<system.data>
<DbProviderFactories>
<add name="Microsoft SQL Server Compact Data Provider"
invariant="System.Data.SqlServerCe.3.5"
description=".NET Framework Data Provider for Microsoft SQL Server Compact"
type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=3.5.1.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</DbProviderFactories>
</system.data>
Doing the above works for my deployed apps; however, when I run my app in debug mode from VS2010, any DB calls that run through the EF come up with this error:
The specified store provider cannot be found in the configuration, or is not valid.
If I remove the entry from my app.config it works fine but stops working for deployed apps.
Is there a happy medium? I’m assuming that the cause of the error is because I have a legit copy of Sql CE installed on my development machine and for whatever reason, registering it in my app.config causes it to break, though I don’t completely understand why.
Tips? Suggestions?
Thanks in advance.
I should have done a little more searching. I found the problem, it seems I need to remove the provider before adding it. When a real install of Sql CE is present, it registers itself in the machine.config, so adding it to the app.config causes it to be registered twice.
This is what should go in the app.config