0

VS2013 update 3, EF 6.1 using Code First, VB

I have both an MVC5 project and a Forms project in place to learn how to effectively use EF 6. Both projects work fine in my local environment and both default to use my .\SQLEXPRESS server. I notice these initial template projects do not have a ConnectionString in their ~.config files. However, the MVC5 project has a defaultConnectionFactory element where the Forms project has nothing related to EF.

1) How are these projects establishing their connection to the SQL server?

2) If I want to connect to a different SQL server do I simply add a ConnectionString element to the ~.config file?

Assuming the answer to (2) above is correct, I would like to first create the ConnectionString to specify exactly the same connection that is currently in use so I have a known spot to work from.

I found what should be valid connection string constructions in Server Explorer, so I have the details of the 'Data Source', 'Initial Catalog', and the 'Integrated Security' flag. What I don't understand is what to use for the name element of the ConnectionString and if that will maintain the applications' connections to the local .\SQLEXPRESS server.

I hope this all made sense...

Thanks.

Best Regards, Alan

Alan
  • 1,587
  • 3
  • 23
  • 43

1 Answers1

0

This was the web.config code I needed to duplicate what was automatically done by the defaultConnectionFactory element:

    <connectionStrings>
      <add name="BlogContext"
      providerName="System.Data.SQLClient"
      connectionString="Data Source=<my pc name here>\SQLEXPRESS;Initial Catalog=EFmigration.BlogContext;Integrated Security=True;" />
    </connectionStrings>

The important points for me were:

1) The name element is simply the same as the Context name

2) You can't forget the profiderName attribute, but note this thread

From this string I can now apply the web.config transformation elements.

Best Regards, Alan

Community
  • 1
  • 1
Alan
  • 1,587
  • 3
  • 23
  • 43