'The network path was not found
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)]
Solution 1:[1]
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. ;)
Solution 2:[2]
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).
Solution 3:[3]
There may be some reasons like:
- Wrong SQL connection string.
- SQL Server in services is not running.
- 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:
- Distributed Transaction Coordinator service
- 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]
Solution 4:[4]
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.
Solution 5:[5]
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();
Solution 6:[6]
As others pointed out this could be more to do with the connectionstring config Make sure,
- user id and password are correct
- Data Source is pointing to correct one , for example if you are using SQL express it will be .\SQLEXPRESS
- Database is pointing to correct name of database Hope that helps.
Solution 7:[7]
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
}
Solution 8:[8]
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.
Solution 9:[9]
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.
Solution 10:[10]
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.
Solution 11:[11]
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>
Solution 12:[12]
If you are using any db , please check connection string also
Solution 13:[13]
When I copied my solution from my pc to another one I had to change the connection string in web.config file. Even if you have the same database name, you should do it for the server name as well.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow