Anyway to check if a SqlConnection has a SqlTransaction open against it
-
Hi, Is there any way to find out if a SqlConnection has an open SqlTransaction? Basically I have an object with a method that accepts a SqlConnection as a parameter. This method is called from a number of different application. Sometimes the SqlConnection has a SqlTransaction and other times it doesn't. So what I need to be able to do is something along the lines of
public bool Post(SqlConnection cn, int ID)
{
SqlTransaction trans;if(cn.HasTransaction)
{
trans = cn.Transaction;
}
else
{
trans = cn.BeginTransaction();
}// some other stuff
return true;
}Is there anyway to get something similar? Thanks, David
-
Hi, Is there any way to find out if a SqlConnection has an open SqlTransaction? Basically I have an object with a method that accepts a SqlConnection as a parameter. This method is called from a number of different application. Sometimes the SqlConnection has a SqlTransaction and other times it doesn't. So what I need to be able to do is something along the lines of
public bool Post(SqlConnection cn, int ID)
{
SqlTransaction trans;if(cn.HasTransaction)
{
trans = cn.Transaction;
}
else
{
trans = cn.BeginTransaction();
}// some other stuff
return true;
}Is there anyway to get something similar? Thanks, David
I rather suspect that you could just check to see if the Transaction is null or not on the command.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
Hi, Is there any way to find out if a SqlConnection has an open SqlTransaction? Basically I have an object with a method that accepts a SqlConnection as a parameter. This method is called from a number of different application. Sometimes the SqlConnection has a SqlTransaction and other times it doesn't. So what I need to be able to do is something along the lines of
public bool Post(SqlConnection cn, int ID)
{
SqlTransaction trans;if(cn.HasTransaction)
{
trans = cn.Transaction;
}
else
{
trans = cn.BeginTransaction();
}// some other stuff
return true;
}Is there anyway to get something similar? Thanks, David
Shouldn't you track that yourself?
-
I rather suspect that you could just check to see if the Transaction is null or not on the command.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
There is no command being passed in, just a connection. So when I create a command object I want to do something like.
SqlTransaction trans = null;
cmd.Connection = cn;if(cn.HasTransaction)
{
trans = cn.Transaction;
}
else
{
trans = cn.BeginTransaction();
}cmd.Transaction = trans;
-
Shouldn't you track that yourself?