SQL Server Compact 4.0 connection string for Entity Framework code first?

c# connection-string ef-code-first entity-framework sql-server-ce

Popular Answer

I utilized SQL Server Compact 4.0 for one of my projects, and my connection string was rather straightforward:

  <connectionStrings>
    <add name="MyDB" 
            connectionString="Data Source=|DataDirectory|MyDB.sdf"
            providerName="System.Data.SqlServerCe.4.0" />
  </connectionStrings>

I believe You ought to examine yourproviderName. I'm not certain ifSystem.Data.SqlClient is the ideal choice.

Do you have NuGet package EntityFramework.SqlServerCompact installed? After installation, System.Data.SqlServerCe.4.0 supplier name is added and must be included in the connection string.

Verify ifSqlServerCompact is added to your providerweb.config .

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="System.Data.SqlServerCe.4.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
    </providers>
  </entityFramework>
  <system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SqlServerCe.4.0" />
      <add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
    </DbProviderFactories>
  </system.data>

14
10/19/2014 9:18:02 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow