Click here to Skip to main content
15,919,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there...
In local hast I have a connection string(web.config) as below

HTML
connectionStrings>
    <add name="bongahConnectionString" connectionString="Data Source=MEHDI-PC;Initial Catalog=bongah;Integrated Security=True"
      providerName="System.Data.SqlClient" />
  </connectionStrings>


and in host there is a connectionstring like this


HTML
data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true


when i try to access to db this error appear


The network path was not found

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ComponentModel.Win32Exception: The network path was not found

Source Error:
C#
Line 78:     {
Line 79:         SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["bongahConnectionString"].ToString());
Line 80:         con.Open();
Line 81:         string query1 = "SELECT ID FROM aparteman WHERE ID=(SELECT MAX(ID)FROM aparteman)";
Line 82:         SqlCommand cmd = new SqlCommand(query1, con);


What can i do?
Posted
Updated 2-Jan-14 3:27am
v3
Comments
Arslan Elahi 2-Jan-14 8:59am    
@mehdi pour ...it simple you have to change your connection string ... network path errors come usually due to wrong connection string

Hi Mehdi,

Data Source=MEHDI-PC;Initial Catalog=bongah;Integrated Security=True

1) In the above connection string, try to replace MEHDI-PC to IP Address it will be more easy to understand in Connection string point of view.(optional)
2) I think you have missed the DB instance name in it.

Sample SQL Server Connection string should look like this
XML
connectionString="SERVER=192.168.xx.xx\SQL2008;DataBase=DatabaseName;Initial Catalog=bongah;UID=Username;pwd=****;"

Hope this helps you a bit.

Regards,
RK
 
Share this answer
 
Use This Code in Web.config

XML
<connectionstrings>
    <add name="NewConnectionString" connectionstring="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\shoping.mdf;Integrated Security=True;User Instance=True" providername="System.Data.SqlClient" />
</connectionstrings>


Now Use this code in FileName.aspx.CS file

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["NewConnectionString"].ConnectionString);
 
Share this answer
 
v2
Comments
m-e-h-d-h-i 17-Jan-14 12:13pm    
yes
but i set this username and password to access my database in host

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