0

I've created this MVC4 web application and went with a local MDF (localdb?). It's located in the \App_Data folder of my project. It's name is SiteDatabase.mdf.

But right now im struggling with the connection string, how can I "link" it up?

I got this:

<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=SiteDatabase;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\SiteDatabase.mdf" providerName="System.Data.SqlClient" />

Where SiteDatabase.mdf is located in my App_Data folder.

The error Im getting:

Server Error in '/' Application.

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.)
Jason94
  • 13,320
  • 37
  • 106
  • 184

2 Answers2

0

Create a udl file, if it connects then the problem is the code / application, if it does not connect, then it's your firewall, connections string, dll library etc. Well the important thing here is probably the connection string. Do the following: create an empty text file and rename it "myconnection.udl". Now double click on the file and it will launch an applet. You can configuer the connection to your database and test it. (it will pick up registered connection libraries etc). If it give OK, then open the udl file in notepad, you will see the correct connection string. Paste to your app connection settings. UDL files are generally misunderstood. They are simply a text file that holds the connection settings. They then call the connection dll. If the udl file works then you have a correct connection string 100%

Ian P
  • 1,724
  • 1
  • 10
  • 12
0

Try add before your connection string

<remove name="LocalSqlServer" />
Rakstit
  • 57
  • 1
  • 13