I am trying to connect to local database file (.mdf) which is located in App_Data folder from asp.net dev project. But it gives me an exception. What I have missed ?
Web.Config:
<connectionStrings >
<add
name="TestLocalDB"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|DB.mdf;Integrated Security=True;Connect Timeout=30"
providerName="System.Data.SqlClient"
/>
</connectionStrings>
code-behind:
string con = ConfigurationManager.ConnectionStrings["TestLocalDB"].ConnectionString;
SqlConnection connection = new SqlConnection(con);
connection.Open(); //here it gives the exception
exception:
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: 26 - Error Locating Server/Instance Specified)