Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 打开和关闭服务中的多个连接时出现SAP Sybase SQL Anywhere NullReference异常_C#_Sql_Nullreferenceexception_Sqlanywhere - Fatal编程技术网

C# 打开和关闭服务中的多个连接时出现SAP Sybase SQL Anywhere NullReference异常

C# 打开和关闭服务中的多个连接时出现SAP Sybase SQL Anywhere NullReference异常,c#,sql,nullreferenceexception,sqlanywhere,C#,Sql,Nullreferenceexception,Sqlanywhere,目前我遇到了一个问题,sapsybassqlanywhere在一个服务中随机抛出NullReference异常,该服务执行大量SQL查询。始终使用块在中创建密码,并正确打开和关闭密码。并行连接不多,但一段时间后(随机)会引发以下异常: 异常:System.NullReferenceException:对象未设置为实例。 bei iAnywhere.Data.SQLAnywhere.SAConnection.Dispose(布尔处理) bei iAnywhere.Data.SQLAnywhere.

目前我遇到了一个问题,
sapsybassqlanywhere
在一个服务中随机抛出
NullReference异常
,该服务执行大量SQL查询。始终使用块在
中创建密码,并正确打开和关闭密码。并行连接不多,但一段时间后(随机)会引发以下异常:

异常:System.NullReferenceException:对象未设置为实例。 bei iAnywhere.Data.SQLAnywhere.SAConnection.Dispose(布尔处理) bei iAnywhere.Data.SQLAnywhere.SAConnection.Close() bei iAnywhere.Data.SQLAnywhere.SAConnection.get_State() bei product.Framework.DAL.ConnectionManager.GetOpenPoolConnection[T](字符串模块名,字符串连接,布尔值resizePoolOnRimteOut,Int64时间 输出,布尔值为(秒) bei product.Framework.DAL.ORM.Sybase.SybaseStack.LoadDataFromDB[T](字符串,其中的部分,字符串连接字符串名,对象[]sa_参数) bei product.Framework.DAL.ORM.Sybase.SybaseStack.LoadData[T](字符串optWherePart,对象[]参数) bei product.PlugIn.DocCenterClient.AS_Modules.DefaultInstanceDataExportModule.DoSingalProcessing() bei System.Threading.ExecutionContext.RunInternal(ExecutionContext ExecutionContext,ContextCallback回调,对象状态,布尔保留同步 十) bei System.Threading.ExecutionContext.Run(ExecutionContext ExecutionContext,ContextCallback回调,对象状态,布尔保留SyncCTX) bei System.Threading.ExecutionContext.Run(ExecutionContext ExecutionContext,ContextCallback回调,对象状态) bei System.Threading.ThreadHelper.ThreadStart()

有人知道这种行为是由什么引起的吗?我们无法找出任何规律性

编辑

using (SAConnection connection = DAL.ConnectionManager.GetOpenPoolConnection<SAConnection>())
{
    var res = connection.Query<Guid>("SELECT InstanceDataGuid FROM AS_EX_Objects WHERE ExchangeObjectId = ?", new { ExchangeObjectId = ic.ItemId.ToString() });
    if (res.Any())
    {
        instanceDataGuid = res.Single<Guid>();
   }
}
internal static T GetOpenPoolConnection<T>(string Connection = "Default") where T : DbConnection
{
    // Read connection string from static dictionary
    string cConnectionString = GetConnectionString(Connection);
    T cToReturn = null;

    if (cConnectionString != null)
    {
        if (typeof(T) == typeof(SqlConnection))
        {
            cToReturn = (new SqlConnection(cConnectionString) as T);
            cToReturn.Open();
        }
        else if (typeof(T) == typeof(SAConnection))
        {
            cToReturn = (new SAConnection(cConnectionString) as T);
            cToReturn.Open();
        }
        else if (typeof(T) == typeof(OdbcConnection))
        {
            cToReturn = (new OdbcConnection(cConnectionString) as T);
            cToReturn.Open();
        }

        return cToReturn;
    }
    else
    {
        return null;
    }
}
打开关闭连接时,会引发异常

编辑

using (SAConnection connection = DAL.ConnectionManager.GetOpenPoolConnection<SAConnection>())
{
    var res = connection.Query<Guid>("SELECT InstanceDataGuid FROM AS_EX_Objects WHERE ExchangeObjectId = ?", new { ExchangeObjectId = ic.ItemId.ToString() });
    if (res.Any())
    {
        instanceDataGuid = res.Single<Guid>();
   }
}
internal static T GetOpenPoolConnection<T>(string Connection = "Default") where T : DbConnection
{
    // Read connection string from static dictionary
    string cConnectionString = GetConnectionString(Connection);
    T cToReturn = null;

    if (cConnectionString != null)
    {
        if (typeof(T) == typeof(SqlConnection))
        {
            cToReturn = (new SqlConnection(cConnectionString) as T);
            cToReturn.Open();
        }
        else if (typeof(T) == typeof(SAConnection))
        {
            cToReturn = (new SAConnection(cConnectionString) as T);
            cToReturn.Open();
        }
        else if (typeof(T) == typeof(OdbcConnection))
        {
            cToReturn = (new OdbcConnection(cConnectionString) as T);
            cToReturn.Open();
        }

        return cToReturn;
    }
    else
    {
        return null;
    }
}
我们使用
sapsqlaywhere 12
作为数据库引擎/服务器,使用
sapsqlaywhere 16
作为客户端组件

编辑

using (SAConnection connection = DAL.ConnectionManager.GetOpenPoolConnection<SAConnection>())
{
    var res = connection.Query<Guid>("SELECT InstanceDataGuid FROM AS_EX_Objects WHERE ExchangeObjectId = ?", new { ExchangeObjectId = ic.ItemId.ToString() });
    if (res.Any())
    {
        instanceDataGuid = res.Single<Guid>();
   }
}
internal static T GetOpenPoolConnection<T>(string Connection = "Default") where T : DbConnection
{
    // Read connection string from static dictionary
    string cConnectionString = GetConnectionString(Connection);
    T cToReturn = null;

    if (cConnectionString != null)
    {
        if (typeof(T) == typeof(SqlConnection))
        {
            cToReturn = (new SqlConnection(cConnectionString) as T);
            cToReturn.Open();
        }
        else if (typeof(T) == typeof(SAConnection))
        {
            cToReturn = (new SAConnection(cConnectionString) as T);
            cToReturn.Open();
        }
        else if (typeof(T) == typeof(OdbcConnection))
        {
            cToReturn = (new OdbcConnection(cConnectionString) as T);
            cToReturn.Open();
        }

        return cToReturn;
    }
    else
    {
        return null;
    }
}

非常感谢

在没有看到您编写代码的情况下,您必须实际进入并评估/检查您正在创建对象实例并处理它们的所有位置。您能否显示用于打开和关闭连接的代码。。?如果您在using中有此功能,则不要显式调用connection.Close()方法已经考虑过发布一些代码,但这发生在不同的点上,但我将添加一些示例。如果代码在如何打开和关闭方面相同/非常一致,则显示每个..@MethodMan ok,在发生这种情况的地方添加了一些代码(在那里使用Dapper)查看此链接它可能会回答您关于
DAL.ConnectionManager.GetOpenPoolConnection
的问题,也可以在您的
ADO网络驱动程序上
这是
32位还是64位
在项目属性下您的
平台目标设置为什么。。?