This line of code
DbProviderFactory factory = DbProviderFactories.GetFactory("Microsoft.SqlServerCe.Client");
throws this exception
System.Configuration.ConfigurationErrorsException:
Failed to find or load the registered
.Net Framework Data Provider.
Although my machine.config file contains the following section
<system.data>
<DbProviderFactories>
<add name="OracleClient Data Provider" invariant="System.Data.OracleClient" description=".Net Framework Data Provider for Oracle" type="System.Data.OracleClient.OracleClientFactory, System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<add name="SqlClient Data Provider" invariant="System.Data.SqlClient" description=".Net Framework Data Provider for SqlServer" type="System.Data.SqlClient.SqlClientFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<add name="SQL Server CE Data Provider" invariant="Microsoft.SqlServerCe.Client" description=".NET Framework Data Provider for Microsoft SQL Server 2005 Compact Edition" type="Microsoft.SqlServerCe.Client.SqlCeClientFactory, Microsoft.SqlServerCe.Client, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</DbProviderFactories>
</system.data>
Am I missing something? Should I look somewhere else? Code like DbProviderFactory factory = SqlCeProviderFactory.Instance works fine.
There are multiple SQL Server CE installs. The Visual Studio tools provides the server explorer and design components and places the SQL Server CE DLLs in a location local to Visual Studio. I needed to install the runtime to get the data provider registered in the machine.config file.