1

I use SQL Server developer edition and would like to use EF code first. I found many articles explaining how to work with either a localdb or SQLExpress. How do I tell my project to rather use my ..\SQL2008 instance?

I'm thinking that somewhere, somehow, one must be able to tell the project to use a specific connectionstring. But where? Adding it to my app.config file doesn't work. This is what I've tried:

<connectionStrings>
    <add name="Context" connectionString="Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=TimeApp;Data Source=Amanda-PC\SQL2008; MultipleActiveResultSets=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
1
  • do you pass the correct Connection string to the constructor of the Context? Commented Sep 30, 2013 at 4:09

1 Answer 1

1

You can specify which connection string to use by passing the name of the connection string to the DbContext.

  public class YourContext : DbContext
  {
     public YourContext()
        : base("Context")
     {
     }
}

See this for more information

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Olav, I found that it is using localdb. Don't know how to tell it to stop using it. Setting the connectionstring and defaultConnectionFactory is just ignored. My constring name is the same as the context, so no need to speficy, but I tried nevertheless, but still no luck.
I'm going to start a new project from scratch and see if I set the constring and defaultConnectionFactory before the first run will work. Will keep you updated

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.