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).
DAL.ConnectionManager.GetOpenPoolConnection
codegur.press/35697729/… also on yourADO NET Drivers
is this32 bit or 64 bit
what do you have yourplatform target
set to under the project properties..? – CorottoDAL.ConnectionManager.GetOpenPoolConnection
so thats no problem :D. In this case it is 64 Bit only. – OldQuery
andSingle
methods? Did you wrote them? Are they implemented using deferred execution? – IsoplethGetOpenPoolConnection
? Given the call stack it's the last place in your code before the error. Next are methods in the Sybase libs; I don't think you could do anything about them except update (if it is available)... – Isopleth// Read connection string from static dictionary string cConnectionString = GetConnectionString(Connection); T cToReturn = null; if (cConnectionString == null) {throw new Exception("Connection String was null!")}; else{.....
– HellenicGetOpenPoolConnection
isnull
. An invalid string would throw some other type of exception, at least whencToReturn.Open()
is called. Maybe you are using a property name or resource name that is looked up to get the connection string that is passed. It really does seem you have to be hittingreturn null
. Have you added a breakpoint on it? – Yarbrough