UniTransaction and ParameterCheck issue (Sql Server)
Posted: Fri 01 Aug 2014 05:44
Hi, im having issues only when mixing UniTransaction and enabling ParameterCheck (using SqlServer and last dotconnect universal version of july 31 2014)
Exception: DeriveParameters requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized.
stacktrace at the end of post
Thanks in advance
sample code
var uniConnection = new UniConnection(MicroConnectionString);
uniConnection.Open();
var uniCommand = new UniCommand(); //uniConnection.CreateCommand();
UniTransaction uniTransaction;
//Start a local transaction
uniTransaction = uniConnection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
//Assign transaction object for a pending local transaction
uniCommand.Transaction = uniTransaction;
uniCommand.Connection = uniConnection;
try
{
uniCommand.CommandType = commandType;
uniCommand.CommandText = commandText;
uniCommand.CommandTimeout = commandTimeOut;
//if (commandType == CommandType.StoredProcedure)
// uniCommand.ParameterCheck = parameterCheck; // ***** Dont work with transaction (throws in ExecuteNonQuery below) using SqlServer as provider
foreach (var p in uniParameters) uniCommand.Parameters.Add(p);
var res = uniCommand.ExecuteNonQuery(); //Here throws if i enable parametercheck
uniCommand.Transaction.Commit();
UpdateParameters(parameters, uniParameters);
return res;
}
catch (Exception ex)
{
uniTransaction.Rollback();
throw new Exception(ex.Message + " Rollback executed!", ex.InnerException);
}
finally
{
uniConnection.Close();
}
StackTrace when exception throws if parametercheck=true
at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async)
at System.Data.SqlClient.SqlCommand.DeriveParameters()
at System.Data.SqlClient.SqlCommandBuilder.DeriveParameters(SqlCommand command)
at Devart.Data.Universal.SqlServerProvider.DeriveParameters(IDbCommand command)
at Devart.Data.Universal.UniCommand.DescribeProcedure(String name)
at Devart.Data.Universal.UniCommand.InternalPrepare(Boolean implicitPrepare, Int32 startRecord, Int32 maxRecords)
at Devart.Common.DbCommandBase.ExecuteDbDataReader(CommandBehavior behavior, Boolean nonQuery)
at Devart.Common.DbCommandBase.ExecuteDbDataReader(CommandBehavior behavior)
at Devart.Common.DbCommandBase.ExecuteNonQuery()
Exception: DeriveParameters requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized.
stacktrace at the end of post
Thanks in advance
sample code
var uniConnection = new UniConnection(MicroConnectionString);
uniConnection.Open();
var uniCommand = new UniCommand(); //uniConnection.CreateCommand();
UniTransaction uniTransaction;
//Start a local transaction
uniTransaction = uniConnection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
//Assign transaction object for a pending local transaction
uniCommand.Transaction = uniTransaction;
uniCommand.Connection = uniConnection;
try
{
uniCommand.CommandType = commandType;
uniCommand.CommandText = commandText;
uniCommand.CommandTimeout = commandTimeOut;
//if (commandType == CommandType.StoredProcedure)
// uniCommand.ParameterCheck = parameterCheck; // ***** Dont work with transaction (throws in ExecuteNonQuery below) using SqlServer as provider
foreach (var p in uniParameters) uniCommand.Parameters.Add(p);
var res = uniCommand.ExecuteNonQuery(); //Here throws if i enable parametercheck
uniCommand.Transaction.Commit();
UpdateParameters(parameters, uniParameters);
return res;
}
catch (Exception ex)
{
uniTransaction.Rollback();
throw new Exception(ex.Message + " Rollback executed!", ex.InnerException);
}
finally
{
uniConnection.Close();
}
StackTrace when exception throws if parametercheck=true
at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async)
at System.Data.SqlClient.SqlCommand.DeriveParameters()
at System.Data.SqlClient.SqlCommandBuilder.DeriveParameters(SqlCommand command)
at Devart.Data.Universal.SqlServerProvider.DeriveParameters(IDbCommand command)
at Devart.Data.Universal.UniCommand.DescribeProcedure(String name)
at Devart.Data.Universal.UniCommand.InternalPrepare(Boolean implicitPrepare, Int32 startRecord, Int32 maxRecords)
at Devart.Common.DbCommandBase.ExecuteDbDataReader(CommandBehavior behavior, Boolean nonQuery)
at Devart.Common.DbCommandBase.ExecuteDbDataReader(CommandBehavior behavior)
at Devart.Common.DbCommandBase.ExecuteNonQuery()