J
joshua drew
This error happens every once in a while. I cannot figure out what is
wrong or why this happens.
This SqlTransaction has completed; it is no longer usable.
public void InsertVisitorTargeter()
{
MyUtils.SqlClient sqlClient = null;
SqlTransaction tran = null;
try
{
sqlClient = MyUtils.SqlClientFactory.CreateSqlClient();
tran = sqlClient.SqlCommand.Connection.BeginTransaction(IsolationLevel.RepeatableRead,
"VisitorTargeter");
sqlClient.SqlCommand.Transaction = tran;
CommitToDatabase(sqlClient);
tran.Commit();
}
catch(Exception ex)
{
tran.Rollback();
throw(ex);
}
finally
{
// release resources
MyUtil.SqlClientFactory.DisposeSqlClient(sqlClient);
}
}
//edited method for ease of reading a bit.
private void CommitToDatabase(MyUtil.SqlClient sqlClient)
{
System.Diagnostics.Trace.Write("Inside CommitToDataBase",
"Targeter");
System.Diagnostics.Trace.Write("Visitor is " + visitorID,
"Targeter");
sqlClient.SqlCommand.CommandText =
"[dbo].[usp_VisitorTargeter_ins]";
sqlClient.SqlCommand.Parameters.Clear();
// create parameters
sqlClient.SqlCommand.Parameters.Add("@RETURN_VALUE",
SqlDbType.Int,4);
sqlClient.SqlCommand.Parameters.Add("@ID",
SqlDbType.UniqueIdentifier);
sqlClient.SqlCommand.Parameters.Add("@Email", SqlDbType.VarChar,
256);
sqlClient.SqlCommand.Parameters["@Email"].Value = email;
sqlClient.SqlCommand.Parameters["@RETURN_VALUE"].Direction =
ParameterDirection.ReturnValue;
sqlClient.SqlCommand.Parameters["@ID"].Direction =
ParameterDirection.Output;
sqlClient.SqlCommand.ExecuteNonQuery();
// check that sproc ran successfully by returning 1 and affecting
one table row only
if ( 0 != (int)sqlClient.SqlCommand.Parameters["@RETURN_VALUE"].Value)
//||
}
I also have a begin tran and then a rollback/commit tran in the sp.
wrong or why this happens.
This SqlTransaction has completed; it is no longer usable.
public void InsertVisitorTargeter()
{
MyUtils.SqlClient sqlClient = null;
SqlTransaction tran = null;
try
{
sqlClient = MyUtils.SqlClientFactory.CreateSqlClient();
tran = sqlClient.SqlCommand.Connection.BeginTransaction(IsolationLevel.RepeatableRead,
"VisitorTargeter");
sqlClient.SqlCommand.Transaction = tran;
CommitToDatabase(sqlClient);
tran.Commit();
}
catch(Exception ex)
{
tran.Rollback();
throw(ex);
}
finally
{
// release resources
MyUtil.SqlClientFactory.DisposeSqlClient(sqlClient);
}
}
//edited method for ease of reading a bit.
private void CommitToDatabase(MyUtil.SqlClient sqlClient)
{
System.Diagnostics.Trace.Write("Inside CommitToDataBase",
"Targeter");
System.Diagnostics.Trace.Write("Visitor is " + visitorID,
"Targeter");
sqlClient.SqlCommand.CommandText =
"[dbo].[usp_VisitorTargeter_ins]";
sqlClient.SqlCommand.Parameters.Clear();
// create parameters
sqlClient.SqlCommand.Parameters.Add("@RETURN_VALUE",
SqlDbType.Int,4);
sqlClient.SqlCommand.Parameters.Add("@ID",
SqlDbType.UniqueIdentifier);
sqlClient.SqlCommand.Parameters.Add("@Email", SqlDbType.VarChar,
256);
sqlClient.SqlCommand.Parameters["@Email"].Value = email;
sqlClient.SqlCommand.Parameters["@RETURN_VALUE"].Direction =
ParameterDirection.ReturnValue;
sqlClient.SqlCommand.Parameters["@ID"].Direction =
ParameterDirection.Output;
sqlClient.SqlCommand.ExecuteNonQuery();
// check that sproc ran successfully by returning 1 and affecting
one table row only
if ( 0 != (int)sqlClient.SqlCommand.Parameters["@RETURN_VALUE"].Value)
//||
}
I also have a begin tran and then a rollback/commit tran in the sp.