To utilize the associated database connection string in Web.config. The mdf database will not operate.

asp.net entity-framework sql-server sql-server-2008 visual-studio

Question

The file neodb.mdf is in my App_Data folder and I can browse the database in the server explorer in visual studio, using built in SQLEXPRESS:

Currently trying to no avail:

 <connectionStrings>
    <add name="EFDbContext" connectionString=".\SQLExpress;AttachDbFilename=|DataDirectory|neodb.mdf; Database=neodb;Trusted_Connection=Yes;" providerName="System.Data.SqlClient"/>
  </connectionStrings>

and

 <connectionStrings>
    <add name="EFDbContext" connectionString="Data Source=.SQLEXPRESS;Database=neodb.mdf;Integrated Security=True" providerName="System.Data.SqlClient"/>
  </connectionStrings>

Also as I understand the *.mdf is an SQL server database file type and .dbo is owner of file when it's included in the initial catalog ? What's the initial catalog anywhere ?

1
10
10/7/2011 1:26:53 PM

Accepted Answer

If you have the *.mdf placed in App_Data folder, using this format works:

<connectionStrings>
  <add name="ConnectionName"
    connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|DatabaseName.mdf;Integrated Security=True;User Instance=True"
    providerName="System.Data.SqlClient" />
</connectionStrings>
14
10/7/2011 1:41:11 PM

Popular Answer

There is a simple way to retrieve the connection string to each database. Double click on "DataBase.mdf" file in Solution Explorer > right click on the "DataBase.mdf" file in Server Explorer > click "Properties" > Now you can see the connection string (under the "Connection" header) in the properties menu!



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow