.net 内部连接致命错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11431079/
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 16:31:31  来源:igfitidea点击:

Internal connection fatal error

.netsql-server

提问by Nezreli

I've recently started receiving this error: "Internal connection fatal error" from my application. The error occurs randomly. When it happens my application is unusable for the next few minutes.

我最近开始从我的应用程序中收到此错误:“内部连接致命错误”。错误是随机发生的。当它发生时,我的应用程序在接下来的几分钟内无法使用。

After careful analysis of the error I've concluded that this error happens in only one method within my application. This method fires a series of simple ordinary SQL queries but it does involve multithreading however all threads should be disposed before this block of code. The error happens always on a specific SQL query. For test I've eliminated this query which resulted in error happening on next in line query.

在仔细分析错误后,我得出结论,此错误仅发生在我的应用程序中的一种方法中。此方法会触发一系列简单的普通 SQL 查询,但它确实涉及多线程,但是所有线程都应在此代码块之前处理。错误总是发生在特定的 SQL 查询上。为了测试,我已经消除了这个查询,它导致下一个在线查询发生错误。

This is stack strace:

这是堆栈跟踪:

Internal connection fatal error.

-------------- Stack trace ---------------
   at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry.IntentionalRethrow(Exception chainException, Exception originalException)
   at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry.RethrowRecommended(Exception chainException, Exception originalException)
   at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry.Handle(Exception exceptionToHandle)
   at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl.HandleException(Exception exceptionToHandle)
   at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception exceptionToHandle, String policyName, ExceptionPolicyFactory policyFactory)
   at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception exceptionToHandle, String policyName)
   at Base.Sql.ExecuteScalar()

Application is built on .NET 3.5 and it obviously uses Enterprise Library Data Access. Application is run on Win2003 Terminal Server and it's using Sql Server 2005 database which is on different server.

应用程序建立在 .NET 3.5 上,显然使用企业库数据访问。应用程序在 Win2003 终端服务器上运行,它使用位于不同服务器上的 Sql Server 2005 数据库。

The method which causes this error is not triggered from GUI but from command line if that is of any significence.

导致此错误的方法不是从 GUI 触发,而是从命令行触发,如果这有任何意义的话。

If someone would suggest where to go from here I would be very grateful.

如果有人建议从这里去哪里,我将不胜感激。

回答by NG.

I faced the similar issue and have devoted quite a time on this issue. So you need to check for all of the following one by one.

我遇到了类似的问题,并在这个问题上花了很多时间。所以你需要一一检查以下所有内容。

  1. You might have left some open connection to database just before giving a call to stored procedure.
  2. This exception comes while calling SqlDataReader.Close() or SqlDataReader.Dispose() - It can be fixed using SqlConnection.Close() instead of SqlDataReader.Close()
  3. Delete your temp files folder?
  4. Look at the usage of the ephemeral ports by the IIS server. The default max no. of ports available is normally 4000. You can increase it if your application is making a lot of database calls.
  1. 在调用存储过程之前,您可能已经离开了一些与数据库的打开连接。
  2. 调用 SqlDataReader.Close() 或 SqlDataReader.Dispose() 时出现此异常 - 它可以使用 SqlConnection.Close() 而不是 SqlDataReader.Close() 修复
  3. 删除临时文件文件夹?
  4. 查看 IIS 服务器对临时端口的使用情况。默认最大数量 可用端口数通常为 4000。如果您的应用程序进行大量数据库调用,您可以增加它。

Let me know if it didn't helped. I might get a chance to learn something new.

如果它没有帮助,请告诉我。我可能有机会学习一些新东西。

回答by Chris Moutray

Weird errors like this are often the result of multi-threading access to objects that are not threadsafe.

像这样的奇怪错误通常是多线程访问非线程安全对象的结果。

I think a couple of things are going wrong here.

我认为这里有一些地方出了问题。

  • reuse of open connection across the threads.
  • reuse of sql client objects across the threads.
  • not closing open connections correctly - are you wrapping your connection creation with a using?
  • 跨线程重用开放连接。
  • 跨线程重用 sql 客户端对象。
  • 没有正确关闭打开的连接 - 您是否用using.

Provide a code example and we might be able to spot the problem...

提供一个代码示例,我们也许能够发现问题......

回答by avinava basu

I and my team have been baffled by this problem for quite sometime. We tried implementing everything , from the try-catch-finally to maintenance of all the coding standards; however this problem kept on occurring whenever multiple users were trying to access the page at the same time. The connection would be broken and problems were arising.At times we even have to restart the entire server for the application to start working. Problem was we were unable to restrict users from using the same connection string thus throwing this error. Ultimately we tried opening and closing the connectionstring with "using", previously we were opening and closing it manually with "dbcon.opne()" and "dbcon.close()", after the dataadapter was able to fetch the data.

我和我的团队一直被这个问题困惑了很长一段时间。我们尝试实现一切,从 try-catch-finally 到所有编码标准的维护;然而,每当多个用户同时尝试访问该页面时,这个问题就会不断发生。连接会中断并出现问题。有时我们甚至必须重新启动整个服务器才能使应用程序开始工作。问题是我们无法限制用户使用相同的连接字符串,从而引发此错误。最终,我们尝试使用“using”打开和关闭连接字符串,之前我们在数据适配器能够获取数据后使用“dbcon.opne()”和“dbcon.close()”手动打开和关闭它。

So what we did, we replaced the same thing with "using" and that kept the whole thing within bracket.

所以我们所做的,我们用“使用”替换了同样的东西,并将整个内容保留在括号内。

using (DBConn = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnect"].ConnectionString)){ the code here--- if (DBConn.State != ConnectionState.Open) DBConn.Open();

using (DBConn = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnect"].ConnectionString)){ 这里的代码--- if (DBConn.State != ConnectionState.Open) DBConn.Open();

}

}

This resolved the problem completely.

这完全解决了问题。

Hope this helps.

希望这可以帮助。

回答by Cobus Kruger

For .NET Core 2.0 or higher, the the error can also occur when you have the following in your .csproj file:

对于 .NET Core 2.0 或更高版本,当您的 .csproj 文件中包含以下内容时,也会发生该错误:

 <ItemGroup>
   <RuntimeHostConfigurationOption Include="System.Globalization.Invariant" Value="true" /> 
 </ItemGroup> 

According to the documentation, this option "enables you to remove application dependencies on globalization data and globalization behavior." Apart from smaller file size, I don't know what the benefits of that are, but SqlConnection doesn't work with it.

根据文档,此选项“使您能够删除应用程序对全球化数据和全球化行为的依赖。” 除了较小的文件大小之外,我不知道这样做的好处是什么,但 SqlConnection 无法使用它。