gpt4 book ai didi

sql-server - SQL Server 异常 : TCP Provider, 错误:0 - 指定的网络名称不再可用

转载 作者:行者123 更新时间:2023-12-02 09:37:59 65 4
gpt4 key购买 nike

早上好!

提前道歉,我确实意识到有人提出了类似的问题,但解决这些问题并没有解决我的问题,因此这篇文章。

在发布异常详细信息之前,这里是总体概述:

我有 .NET 4.0 智能桌面应用程序,使用 SQL Server(2005 和 2008r2)进行数据存储。在数据库中,我有一个表,用于记录实体何时更改。这允许应用程序的其他实例检查更改并重新加载某些数据。该表有三个字段:

Id [int], EntityName [nvarchar(4000)], ChangeDateTime [datetime]

Id 是主键,ChangeDateTime 字段上有一个索引。

为了实现此目的,应用程序会以一定的时间间隔或在执行操作时检查此表,通过检索特定实体的最新更改日期时间并将其与内部存储的值进行比较来查看是否发生更新。

查询如下所示:

Query: SELECT TOP(@p2) MAX([BondFM].[dbo].[EntityTypeChangedLog].[ChangeDateTime]) AS [ChangeDateTime] FROM [BondFM].[dbo].[EntityTypeChangedLog]   WHERE ( [BondFM].[dbo].[EntityTypeChangedLog].[ChangedEntityTypeName] = @p3)
Parameter: @p2 : Int64. Length: 0. Precision: 0. Scale: 0. Direction: Input. Value: 1.
Parameter: @p3 : String. Length: 4000. Precision: 0. Scale: 0. Direction: Input. Value: "SampleEntityName".

因此该表仅接收来自正在运行的应用程序的两个交互:

  • 如上所示的 Select 请求,用于检索实体的最新更新日期时间
  • 当实体发生更改以添加新行时发​​出插入请求

问题是,在执行 select 语句时,我遇到了许多以下类型的异常:

Message : An exception was caught during the execution of a retrieval query: A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - The specified network name is no longer available.).

有时它也会出现:

  • TCP 提供程序,错误:0 - 信号量超时期限已过期或
  • TCP 提供程序,错误:0 - 远程主机强制关闭现有连接。

此外,我得到以下内部异常,这并没有帮助我缩小问题范围:

    Inner Exception
---------------
Type : System.Data.SqlClient.SqlException, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - The specified network name is no longer available.)
Source : .Net SqlClient Data Provider
Help link :
Errors : System.Data.SqlClient.SqlErrorCollection
Class : 20
LineNumber : 0
Number : 64
Procedure :
Server : SQLServer
State : 0
ErrorCode : -2146232060
Data : System.Collections.ListDictionaryInternal
TargetSite : Void OnError(System.Data.SqlClient.SqlException, Boolean)
Stack Trace : at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
at System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error)
at System.Data.SqlClient.TdsParserStateObject.ReadSni(DbAsyncResult asyncResult, TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParserStateObject.ReadNetworkPacket()
at System.Data.SqlClient.TdsParserStateObject.ReadBuffer()
at System.Data.SqlClient.TdsParserStateObject.ReadByte()
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteScalar()
at SD.LLBLGen.Pro.ORMSupportClasses.RetrievalQuery.ExecuteScalar()

我已经阅读并测试了各种连接问题,但这些问题没有帮助,我想知道表内是否发生了某些事情(例如锁?)导致了这种情况?

感谢您的阅读,如有任何帮助或指点,我们将不胜感激!

迈克

最佳答案

您可以尝试增加连接字符串中的连接超时。

    private static void OpenSqlConnection()
{
string connectionString = GetConnectionString();
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
Console.WriteLine("State: {0}", connection.State);
Console.WriteLine("ConnectionTimeout: {0}",
connection.ConnectionTimeout);
}
}

static private string GetConnectionString()
{
// To avoid storing the connection string in your code,
// you can retrieve it from a configuration file, using the
// System.Configuration.ConfigurationSettings.AppSettings property
return "Data Source=(local);Initial Catalog=AdventureWorks;"
+ "Integrated Security=SSPI;Connection Timeout=30";
}

关于sql-server - SQL Server 异常 : TCP Provider, 错误:0 - 指定的网络名称不再可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20729627/

65 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com