JNYRanger
JNYRanger

Reputation: 7097

Changing Underlying EF Database

I'm surprised this hasn't been asked before, but here goes:

I have a WCF Service that currently uses Entity Framework with SQL Compact as the underlying datasource. Some requirements changed and I can no longer use an embedded database for this, so we now have a fully fledged SQL Server that mirrors the schema of the original SQL Compact database, and is populated with the exact same data. I am trying to figure out how to change the underlying datasource now for Entity Framework, but it doesn't quite look like there is a straight forward way to do this.

Here is my configuration and my attempt to modify it (commented out lines is what was originally there:

<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="System.Data.SqlServer" />
      </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>
<connectionStrings>
    <!--<add name="ApplicationServiceDataEntities" connectionString="metadata=res://*/LoanAppEntity.csdl|res://*/LoanAppEntity.ssdl|res://*/LoanAppEntity.msl;provider=System.Data.SqlServerCe.4.0;provider connection string=&quot;data source=|DataDirectory|\ApplicationServiceData.sdf&quot;" providerName="System.Data.EntityClient" />-->
<add name="ApplicationServiceDataEntities" connectionString="Data Source=REMOVED;Initial Catalog=LoanAppData;persist security info=True; user id=REMOVED;password=REMOVED;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
</connectionStrings>

I'm not sure what I need to modify in this since I've never done it before. Most of the things I've seen online show how to do it at runtime, but I want this changed completely. The main thing that's confusing me is that I'm not familiar with portions of the connection string including the metadata & res://, and the ssdl / csdl / msl extensions seen in the configuration.

Upvotes: 0

Views: 94

Answers (1)

mituw16
mituw16

Reputation: 5250

You simply need to comment out or remove your old connection string and add a new one that points to your new SQL Server

EDIT Changing connection string to EF generated model

 <connectionStrings>
    <add name="ApplicationServiceDataEntities" connectionString="metadata=res://*/LoanAppEntity.csdl|res://*/LoanAppEntity.ssdl|res://*/LoanAppEntity.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=DATABASEIP;initial catalog=DATABASENAME;persist security info=True;user id=DATABASEUSER;password=DATABASEPASS;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />  
 </connectionStrings>

Upvotes: 1

Related Questions