Reputation: 3333
I have data context
public class KOATUUContext : DbContext
{
static KOATUUContext()
{
Database.SetInitializer<KOATUUContext>(null);
}
public KOATUUContext()
: base("KOATUU")
{
}
public DbSet<KOATUU> KOATUUs { get; set; }
public DbSet<Region> Regions { get; set; }
public DbSet<TerType> TerTypes { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new KOATUUMap());
modelBuilder.Configurations.Add(new RegionMap());
modelBuilder.Configurations.Add(new TerTypeMap());
base.OnModelCreating(modelBuilder);
}
}
I want my context to load correct connection string so I have specified the following in root web.config
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="RealEstateAgency"
connectionString="data source=DIMIAS-PC\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
<add name="KOATUU" connectionString="Data Source=streamer2005\tc;Initial Catalog=KOATUU;Persist Security Info=True;User ID=*****;Password=*****;MultipleActiveResultSets=True"
providerName="System.Data.SqlClient" />
Could you tell me what problem might be? The result of execution - default connection string to SQL Express.
Upvotes: 0
Views: 566
Reputation: 4803
I've only used database first and when the DbContext is generated the connection name is not specified like this:
public KOATUUContext()
: base("KOATUU")
{
}
but like this:
public KOATUUContext()
: base("name=KOATUU")
{
}
Perhaps that's the issue.
Upvotes: 1