The network path was not found

40

I'm running my code and getting this error. But what does it mean?

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:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[Win32Exception (0x80004005): The network path was not found]

[SqlException (0x80131904): 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)]

.net
database
networking
asked on Stack Overflow Jan 30, 2014 by user3278908 • edited Jan 30, 2014 by Kad

12 Answers

45

This is probably related to your database connection string or something like that.

I just solved this exception right now. What was happening is that I was using a connection string intended to be used when debugging in a different machine (the server).

I commented the wrong connection string in Web.config and uncommented the right one. Now I'm back in business... this is something I forget to look at after sometime not working in a given solution. ;)

answered on Stack Overflow Oct 17, 2014 by Leniel Maccaferri
7

You will also get this exact error if attempting to access your remote/prod db from localhost and you've forgotten that this particular hosting company requires VPN logon in order to access the db (do i feel silly).

answered on Stack Overflow Apr 25, 2018 by puddleglum • edited Apr 25, 2018 by puddleglum
3

There may be some reasons like:

  1. Wrong SQL connection string.
  2. SQL Server in services is not running.
  3. Distributed Transaction Coordinator service is not running.

First try to connect from SQL Server Management Studio to your Remote database. If it connects it means problem is at the code side or at Visual Studio side if you are using the one.

Check the connectionstring, if the problem persists, check these two services:

  1. Distributed Transaction Coordinator service
  2. SQL Server services.

Go in services.msc and search and start these two services.

The above answer works for the Exception: [Win32Exception (0x80004005): The network path was not found]

answered on Stack Overflow Oct 23, 2016 by Kshitij Jhangra
3

Possibly also check the sessionState tag in Web.config

Believe it or not, some projects I've worked on will set a connection string here as well.

Setting this config to:

<sessionState mode="InProc" />

Fixed this issue in my case after checking all other connection strings were correct.

answered on Stack Overflow Jan 18, 2017 by ooXei1sh
2

Same problem with me. I solved this by adding @ before connection string (C# has a thing called 'String Literals') like so:

SqlConnection sconnection = new SqlConnection(@"Data Source=(Localdb)\v11.0; Initial Catalog=Mydatabase;Integrated Security=True");

sconnection.Open();
answered on Stack Overflow Mar 4, 2016 by (unknown user) • edited Nov 26, 2016 by Ivan Rubinson
2

As others pointed out this could be more to do with the connectionstring config Make sure,

  1. user id and password are correct
  2. Data Source is pointing to correct one , for example if you are using SQL express it will be .\SQLEXPRESS
  3. Database is pointing to correct name of database Hope that helps.
answered on Stack Overflow Dec 22, 2016 by Nathan Senevirathne
1

check your Connection String Properly. Check that the connection is open.

String CS=ConfigurationManager.COnnectionStrings["DBCS"].connectionString;
  if(!IsPostBack)
    {enter code here
   SqlConnection con = new SqlConnection(CS);
        con.Open();
    SqlCommand cmd = new SqlCommand("select * from tblCountry", con);
     SqlDataAdapter da = new SqlDataAdapter(cmd);
     DataTable dt = new DataTable();
da.Fill(dt);
//Bind data
}
answered on Stack Overflow Apr 30, 2019 by Priyank Raunak • edited Apr 30, 2019 by Robert
0

I recently had the same issue. It's more likely that your application can not connect to database server due to the network issues.

In my case I was connected to wrong WiFi.

answered on Stack Overflow Dec 15, 2017 by Komal Narang
0

At The Beginning, I faced the same error but with a different scenario. I was having two connection strings, one for ado.net, and the other was for the EntityFramework, Both connections where correct. The problem specifically was within the edmx file of the EF, where I changed the ProviderManifestToken="2012" to ProviderManifestToken="2008" therefore, the application worked fine after that.

answered on Stack Overflow Aug 6, 2020 by Mahmoud Nasr
0

In my case, I had generated DbContext from an existing database. I had my connection string set in appSettings.json file; however, when I generated the class files by scaffolding the DbContext class it had incorrect connection string.

So make sure your connection string is proper in appSettings.json file as well as in DbContext file. This will solve your issue.

answered on Stack Overflow Sep 27, 2020 by noobprogrammer
0

On my end, the problem was an unsuccessful connection to the VPN (while working from home). And yeah, the connectionString was using a context from remote server. Which resulted in the following error:

<Error>
  <Message>An error has occurred.</Message>
  <ExceptionMessage>The network path was not found</ExceptionMessage>
  <ExceptionType>System.ComponentModel.Win32Exception</ExceptionType>
  <StackTrace/>
</Error>
answered on Stack Overflow Jan 15, 2021 by Zdravko Kolev
0

If you are using any db , please check connection string also

answered on Stack Overflow Mar 6, 2021 by Kathir M

User contributions licensed under CC BY-SA 3.0