One observation is that you are giving the full path of the mdf
file in the connection string. |DataDirectory|
directory automatically points to the App_Date
folder. so no need to give the full physical path of the mdf
file. this should also work -
<add name="ApplicationServices"
connectionString="data source=.\SQLMIRZA;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\ASPNETDB.MDF;User Instance=true"
providerName="System.Data.SqlClient" />
to connect to mdf
file directly you need SQLEXPRESS
installed on your machine. check if your web server has SQLEXPRESS
instance installed.
if you instead attach the file to MSSQLSERVER
instance. then your connection string should be changed to something like this -
<add name="ApplicationServices"
connectionString="data source=(local);Initial Catalog=ASPNETDB;Integrated Security=SSPI;User Instance=true" providerName="System.Data.SqlClient" />
if this connection string doesn't work on your local machine then you can keep both in your web.config
and comment out one. something like this -
<!-- LOCAL -->
<add name="ApplicationServices"
connectionString="data source=.\SQLMIRZA;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\ASPNETDB.MDF;User Instance=true"
providerName="System.Data.SqlClient" />
<!--REAL-->
<!--<add name="ApplicationServices"
connectionString="data source=.\SQLMIRZA;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\ASPNETDB.MDF;User Instance=true"
providerName="System.Data.SqlClient" />-->
here I have commented out the real/web connection string, so it will work on local machine.
before deploying just just reverse the comments and it will work on web.