SAP Sybase SQL Anywhere NullReference在打开和关闭服务中的多个连接时发生异常

Ben*_*dEg 10 c# sql sqlanywhere nullreferenceexception

目前我遇到的问题是,在服务中SAP Sybase SQL Anywhere随机抛出NullReference Exceptions,执行大量的SQL查询.始终在using块中创建连接并正确打开和关闭.没有很多并行连接,但一段时间后(随机)抛出以下异常:

异常: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 ](String ModuleName,String Connection,Boolean resizePoolOnRimteOut,Int64 Time Out,Boolean isSecondTry)bei product.Framework.DAL.ORM.Sybase.SybaseStack.LoadDataFromDB [T](String where_part,String connectionStringName,Object [] sa_params)bei product. Framework.DAL.ORM.Sybase.SybaseStack.LoadData [T](String optWherePart,Object [] parameter)bei product.PlugIn.DocCenterClient.AS_Modules.DefaultInstanceDataExportModule.DoSingalProcessing()bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,ContextCallback callback,Object state,Boolean preserveSyncCt x)bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback callback,Object state,Boolean preserveSyncCtx)bei System.Threadi ng.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback callback,Object state)bei System.Threading.ThreadHelper.ThreadStart()

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

编辑

打开关闭连接时抛出异常.

编辑

我们SAP SQL Anywhere 12用作数据库引擎/服务器和SAP SQL Anywhere 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>();
   }
}
Run Code Online (Sandbox Code Playgroud)

GetOpenPoolConnection只需创建一个新的SAConnection并打开它.

编辑

导致这种情况的所有错误都应该解决,因为我们使用了更新版本的错误ADO .Net Driver.例如:http://sqlasupport.sap.com/readme/sqla1201.html

案例:

  1. 工程案例#797124
  2. 工程案例#741721
  3. 工程案例#738144

编辑

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;
    }
}
Run Code Online (Sandbox Code Playgroud)

非常感谢!