Currently I've the problem that SAP Sybase SQL Anywhere randomly throws NullReferenceException
s in a service which executes a lot of sql queries. The connections are always created in a using
block and opened & closed correctly. There are not many parallel connections, but after a while (randomly) the following exception is thrown when opening and closing connections:
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()
Does someone know what is causing this behavior? We could not figure out any regularity behind it.
The exception is being thrown in GetOpenPoolConnection
, which creates a new SAConnection
and opens it:
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;
}
}
This function is called as:
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>();
}
}
We are using SAP SQL Anywhere 12 as database engine/server and SAP SQL Anywhere 16 as client component. The project and DB driver are 64-bit only. All the bugs that cause this should be fixed in the version of the ADO .Net Driver we're using (in the bugfixes, see engineering cases #797124, #741721 and #738144).