1

I use login control in asp.net. this control creating a aspnetdb.mdf file in app_data folder and there is not any code in web config for connection to this db. in local web is working as correct but when web on IIs can not to conection to the aspnetdb. how to manage connection to aspnetdb by web config? I use follow cod in my web.config but when aspnetdb attach to sqlserver the web not working :

<add name="ApplicationServices"
         connectionString="data source=.\SQLMIRZA;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|ASPNETDB.MDF;User Instance=true"
     providerName="System.Data.SqlClient" />
mirza
  • 766
  • 2
  • 7
  • 12

1 Answers1

1

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.

th1rdey3
  • 4,176
  • 7
  • 30
  • 66