Click here to Skip to main content
15,894,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have hosted a website. The dataconnection I am using is (web.config file)
XML
<add name="dbTestConnectionString" connectionstring="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\dbTest.mdf;Integrated Security=True;User Instance=True" providername="System.Data.SqlClient" />


It works fine on the localhost but when run over the internet, it gives error that access to databse is not possible. (please visit http://www.ezitek.somee.com for detailed error)
I think I need to change the connection string, but I do not know what to do.

When hosted, my database is in App_Data folder of my solution, which has been uploaded as it is.

My host has given me the following detail:

Website local path: d:\DZHosts\LocalUser\fsehgal\www.ezitek.somee.com
Protected local path: d:\DZHosts\LocalUser\fsehgal\Protected.ezitek.somee.com

Please advise what to do to avoid this error.

Thank you very much.
With best regards,
Furqan
Posted
Updated 14-Sep-11 21:37pm
v3
Comments
Herman<T>.Instance 15-Sep-11 3:24am    
is there an sqlexpress db installed on the webserver?
Herman<T>.Instance 15-Sep-11 3:25am    
source . means localhost.

use connection string as
C#
Data Source=OMX11SFD;Initial Catalog=omx;Persist Security Info=True;User ID=sa;Password=uuuu@!"

in your web config file.
Hope it Works.
 
Share this answer
 
Comments
Furqan Sehgal 15-Sep-11 3:36am    
Mr. Patel thanks for the reply. Where does my database name fit? Could you plese give me complete statement to replace with my connection string
"<add name="dbTestConnectionString" connectionstring="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\dbTest.mdf;Integrated Security=True;User Instance=True" providername="System.Data.SqlClient">"
uspatel 15-Sep-11 4:20am    
in my example database name is omx as
Initial Catalog=omx
uspatel 15-Sep-11 4:21am    
Data Source=.\SQLEXPRESS;Initial Catalog=dbTest;Integrated Security=True
uspatel 15-Sep-11 5:35am    
pass full data source name rather than .\SqlExpress
uspatel 15-Sep-11 6:00am    
If you use sql server, then if you connect to database engine ,then a login window appears in sql server, the Server name in this window is your data source name.
I think ConnectionString Problem you try this code.

Use bellow code in Web.cofig
XML
<connectionStrings>
   <!--<add name="OsmEmpConString" connectionString="Data Source=.\sqlexpress;Initial Catalog=Reg.Mdf; "  providerName="System.Data.SqlClient" />-->
   <add name="OsmEmpConString" connectionString="Data Source=.\sqlexpress;Integrated Security=SSPI;AttachDBFilename=C:\Documents and Settings\Administrator\My Documents\Downloads\Rags_Modified\Rags\Rags\App_Data\Reg.mdf;User Instance=true" providerName="System.Data.SqlClient"/>

   <add name="SomeDataBase" connectionString="Data Source=.\SQLEXPRESS; AttachDbFilename=C:\Documents and Settings\Administrator\My Documents\Downloads\Rags_Modified\Rags\Rags\App_Data\Reg.mdf; Integrated Security=True; Connect Timeout=30; User Instance=True" providerName="System.Data.SqlClient"/>

   <!--<add name="SomeDataBase" connectionString="Data Source=.\SQLEXPRESS; AttachDbFilename=C:\App_Data\Reg.mdf; Integrated Security=True; Connect Timeout=30; User Instance=True"  providerName="System.Data.SqlClient" />-->

 </connectionStrings>


In code behind

string constr = ConfigurationManager.ConnectionStrings["SomeDataBase"].ToString();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900