访问SQL Server 2019时偶尔出现随机C#崩溃

问题描述

我有一个从未在SQL Server 2012上出现过问题的应用程序,但是现在尝试在启动时访问SQL Server 2019时偶尔会崩溃。

这是事件日志:

Application: MyApplication.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ComponentModel.Win32Exception

Exception Info: System.Data.SqlClient.SqlException
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(System.Data.ProviderBase.DbConnectionPoolIdentity,System.Data.SqlClient.SqlConnectionString,System.Data.SqlClient.SqlCredential,System.Object,System.String,System.Security.SecureString,Boolean,System.Data.SqlClient.SessionData,System.Data.ProviderBase.DbConnectionPool,Boolean)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(System.Data.Common.DbConnectionOptions,System.Data.Common.DbConnectionPoolKey,System.Data.Common.DbConnection,System.Data.Common.DbConnectionOptions)
   at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(System.Data.ProviderBase.DbConnectionPool,System.Data.Common.DbConnectionOptions,System.Data.Common.DbConnectionOptions)
   at System.Data.ProviderBase.DbConnectionPool.CreateObject(System.Data.Common.DbConnection,System.Data.ProviderBase.DbConnectionInternal)
   at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(System.Data.Common.DbConnection,System.Data.ProviderBase.DbConnectionInternal)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(System.Data.Common.DbConnection,UInt32,System.Data.ProviderBase.DbConnectionInternal ByRef)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(System.Data.Common.DbConnection,System.Threading.Tasks.TaskCompletionSource`1<System.Data.ProviderBase.DbConnectionInternal>,System.Data.ProviderBase.DbConnectionInternal ByRef)
   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(System.Data.Common.DbConnection,System.Data.ProviderBase.DbConnectionInternal,System.Data.ProviderBase.DbConnectionInternal ByRef)
   at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(System.Data.Common.DbConnection,System.Data.ProviderBase.DbConnectionFactory,System.Data.Common.DbConnectionOptions)
   at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(System.Data.Common.DbConnection,System.Data.Common.DbConnectionOptions)
   at System.Data.SqlClient.SqlConnection.TryOpenInner(System.Threading.Tasks.TaskCompletionSource`1<System.Data.ProviderBase.DbConnectionInternal>)
   at System.Data.SqlClient.SqlConnection.TryOpen(System.Threading.Tasks.TaskCompletionSource`1<System.Data.ProviderBase.DbConnectionInternal>)
   at System.Data.SqlClient.SqlConnection.Open()
   at System.Data.Common.DbDataAdapter.FillInternal(System.Data.DataSet,System.Data.DataTable[],Int32,System.Data.IDbCommand,System.Data.CommandBehavior)
   at System.Data.Common.DbDataAdapter.Fill(System.Data.DataTable[],System.Data.CommandBehavior)
   at System.Data.Common.DbDataAdapter.Fill(System.Data.DataTable)
   at MyApplication.Program.MyDatabaseMethod(System.String)
   at MyApplication.Program.Main(System.String[])

这是它崩溃的方法:

public static string MyDatabaseMethod()
{
    DataTable dt = new DataTable();

    string query = "SELECT TOP 1 col1 FROM mydatabase.dbo.mytable";
    SqlDataAdapter da = new SqlDataAdapter(query,myConnectionString);

    da.Fill(dt);

    string data = dt.Rows[0].Field<string>("col1");
    return data;
}

这90%的时间有效,但是偶尔的崩溃变得成问题。错误看起来像超时吗?该数据库非常繁忙,并且每晚晚上同时连接该应用程序的多个实例(〜20个),因此我想知道一次登录的数量是否存在并发问题。查询本身正在访问的表不超过30行。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...