I enumerated the available data providers on my PC with:
Code Snippet
System.Reflection.Assembly[] myAssemblies = System.Threading.Thread.GetDomain().GetAssemblies();
The important entry is:
"SQL Server CE Data Provider"
".NET Framework Data Provider for Microsoft SQL Server 2005 Mobile Edition"
"Microsoft.SqlServerCe.Client"
"Microsoft.SqlServerCe.Client.SqlCeClientFactory, Microsoft.SqlServerCe.Client, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"
When executing:
Code SnippetdataFactory = DbProviderFactories.GetFactory("System.Data.SqlServerCe");
I got at first this error run time message:
Failed to find or load the registered .Net Framework Data Provider.
I added a reference to "Microsoft.SqlServerCe.Client" at C:\Programme\Microsoft Visual Studio 8\Common7\IDE\Microsoft.SqlServerCe.Client.dll and the program runs.
Of course, it uses "Microsoft.SqlServerCe.Client" instead of "System.Data.SqlServerCe". Laxmi Narsimha Rao ORUGANTI from Microsoft writes in the post "SSev and Enterprise Library" that "Microsoft.SqlServerCe.Client" is not meant to be used and that we should add the following entry to the machine.config file:
Code Snippet<add name="SQL Server Everywhere Edition Data Provider" invariant="System.Data.SqlServerCe" description=".NET Framework Data Provider for Microsoft SQL Server Everywhere Edition" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
After changing the code to: Code Snippet
dataFactory = DbProviderFactories.GetFactory("Microsoft.SqlServerCe.Client");
I get the same error message as before, even after adding a reference to "System.Data.SqlServerCe" at C:\Programme\Microsoft Visual Studio 8\Common7\IDE\System.Data.SqlServerCe.dll.
Any suggestion what I should do ? Just use "Microsoft.SqlServerCe.Client" ? Anyway, I dont like the idea that I have to change the machine.config file, since I want to use click once deployment.