客户定期“不支持嵌套/并发事务”。错误。在我这边不可重复,但试图了解它是如何发生的。它只发生在以下方法中:
public DataTable ExecuteDataTable(CommandType type, string query, params NpgsqlParameter[] parameters)
{
NpgsqlCommand command = PrepareCommand(type, query, parameters);
// Use transaction for functions with refcursors. This is necessary to prevent cursors
// returned by refcursor function from closing after the implicity transaction is finished
// (just after we do the function call).
NpgsqlTransaction t = sqlConnection.BeginTransaction();
try
{
NpgsqlDataAdapter da = new NpgsqlDataAdapter(command);
System.Data.DataSet ds = new System.Data.DataSet();
// Fill the DataSet using default values for DataTable names, etc
da.Fill(ds);
t.Commit();
// Detach the SqlParameters from the command object, so they can be used again
command.Parameters.Clear();
return ds.Tables[0];
}
catch (Exception e)
{
// Commit all transactions so connection can be used again (Npgsql does not allow nested transactions)
t.Rollback();
// Log error and problem query
LogError(e);
// Throw same exception to a higher level for correct handling
throw e;
}
}
如果出现错误,我总是尝试回滚以避免嵌套事务,但是在某些安装中它会定期发生。是Npgsql问题还是实现中的东西?怎么会发生这种情况?如果2个进程同时从不同的类,应用程序运行此方法,这是否与连接池或其他东西连接?
调用堆栈:
2013年10月8日 13:00:27.6038 | Common.Logging.NLog.NLogLogger.WriteInternal |信息|招聘 DEFAULT.SQLServerSyncScheduledJob抛出JobExecutionException: | System.InvalidOperationException:嵌套/并发事务 不受支持。在 Npgsql.NpgsqlConnection.BeginTransaction(IsolationLevel level)at Npgsql.NpgsqlConnection.BeginTransaction()at DbFramework.PgDataAccess.ExecuteDataTable(CommandType type,String query,NpgsqlParameter []参数)