Intan
Intan

Reputation: 143

Where is default connection of Entity Framework define?

I create a ASP.NET Web Application with Entity Framework. My web.config is like this

<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
<providers>
  <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>

I want to view my database in SQL Server Management Studio. I couldn't find where is server that stored my data in Entity Framework. Until i'm using Glimpse to see where it is. So my database created in .\SQLEXPRESS. I want to change default connection into another server. I have tried something like this

<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
  <parameters>
    <parameter value="v11.0" />
  </parameters>
</defaultConnectionFactory>
<providers>
  <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>

But it caused an error ArgumentException. So what am i supposed to do to change default connection server?

I'm using Code First Approach to create the database

Upvotes: 0

Views: 3257

Answers (1)

mzonerz
mzonerz

Reputation: 1250

Please check below example for web.config

<configuration>
   <configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
          </configSections>
          <connectionStrings>
            <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-IHIPosterPresentationApp-20160104113839;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-IHIPosterPresentationApp-20160104113839.mdf" providerName="System.Data.SqlClient" />

            <add name="IHIPosterAppEntities" connectionString="metadata=res://*/Models.IHIPosterAppDbEntityModel.csdl|res://*/Models.IHIPosterAppDbEntityModel.ssdl|res://*/Models.IHIPosterAppDbEntityModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\SQLEXPRESS;initial catalog=IHIPosterAppDev;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
          </connectionStrings>
        <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
      </entityFramework>
    </configuration>

Upvotes: 1

Related Questions