提问人:BendEg 提问时间:6/15/2016 最后编辑:outisBendEg 更新时间:12/8/2022 访问量:818
在服务中打开和关闭多个连接时出现 SAP Sybase SQL Anywhere NullReference 异常
SAP Sybase SQL Anywhere NullReference Exception when openening and closing many connections in a service
问:
目前,我遇到了一个问题,即SAP Sybase SQL Anywhere随机抛出一个执行大量sql查询的服务。连接总是在一个块中创建,并正确打开和关闭。并行连接不多,但一段时间后(随机)打开和关闭连接时会引发以下异常:NullReferenceException
using
Exception: System.NullReferenceException: The object was not set to an instance. bei iAnywhere.Data.SQLAnywhere.SAConnection.Dispose(Boolean disposing) 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.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) bei System.Threading.ThreadHelper.ThreadStart()
有人知道是什么导致了这种行为吗?我们无法弄清楚它背后的任何规律性。
抛出异常,这将创建一个新的并打开它:GetOpenPoolConnection
SAConnection
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>();
}
}
我们使用 SAP SQL Anywhere 12 作为数据库引擎/服务器,使用 SAP SQL Anywhere 16 作为客户端组件。项目和数据库驱动程序仅为 64 位。导致此问题的所有 bug 都应在我们使用的 ADO .Net 驱动程序版本中修复(在 bug 修复中,请参阅工程案例 #797124、#741721 和 #738144)。
答: 暂无答案
评论
DAL.ConnectionManager.GetOpenPoolConnection
ADO NET Drivers
32 bit or 64 bit
platform target