.net 找不到网络路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21448728/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 12:37:31  来源:igfitidea点击:

The network path was not found

.netdatabasenetworking

提问by user3278908

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

未找到网络路径说明:在执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。

异常详细信息:System.ComponentModel.Win32Exception:未找到网络路径

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.

执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常来源和位置的信息。

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)]

[Win32Exception (0x80004005): 网络路径未找到]

[SqlException (0x80131904): 与 SQL Server 建立连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。(提供程序:命名管道提供程序,错误:40 - 无法打开与 SQL Server 的连接)]

回答by Leniel Maccaferri

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

这可能与您的数据库连接字符串或类似的东西有关。

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

我现在刚刚解决了这个异常。发生的事情是我使用了一个连接字符串,用于在不同的机器(服务器)中进行调试。

I commented the wrong connection stringin Web.configand 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. ;)

我评论了错误的连接字符串Web.config,并注释掉正确的。现在我又重新开始工作了……这是我在一段时间没有在给定的解决方案中工作后忘记看的东西。;)

回答by puddleglum

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).

如果尝试从本地主机访问您的远程/生产数据库,并且您忘记了该特定托管公司需要 VPN 登录才能访问数据库(我觉得很傻),您也会得到这个确切的错误。

回答by Kshitij Jhangra

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.
  1. 错误的 SQL 连接字符串。
  2. 服务中的 SQL Server 未运行。
  3. 分布式事务协调器服务未运行。

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.

首先尝试从 SQL Server Management Studio 连接到远程数据库。如果它连接,则意味着问题出在代码端或 Visual Studio 端(如果您正在使用)。

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

检查连接字符串,如果问题仍然存在,请检查这两个服务:

  1. Distributed Transaction Coordinator service
  2. SQL Server services.
  1. 分布式事务协调器服务
  2. SQL Server 服务。

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

进入 services.msc 并搜索并启动这两个服务。

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

以上答案适用于异常:[Win32Exception (0x80004005): The network path was not found]

回答by Nathan Senevirathne

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.
  1. 用户名和密码正确
  2. 数据源指向正确的一个,例如,如果您使用 SQL express,它将是 .\SQLEXPRESS
  3. 数据库指向正确的数据库名称希望有帮助。

回答by ooXei1sh

Possibly also check the sessionStatetag in Web.config

也可能检查sessionState标签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.

在检查所有其他连接字符串都正确后,在我的情况下修复了这个问题。

回答by ooXei1sh

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

和我一样的问题。我通过@在连接字符串之前添加(C# 有一个叫做“字符串文字”的东西)来解决这个问题,如下所示:

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

sconnection.Open();

回答by Priyank Raunak

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
}

回答by Komal Narang

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.

就我而言,我连接到错误的 WiFi。