SqlTransaction problem

  • Thread starter Thread starter pers
  • Start date Start date
P

pers

Hi all
In my web application I have following code:
SqlConnection con = new SqlConnection("Data Source=.;Connect Timeout=15;
Initial Catalog=SaamicAcc1;Integrated Security=True");

SqlCommand com = new SqlCommand("",con);


com.Parameters.AddWithValue("@A", "somevalue");

com.CommandText = "Insert into Test (Name) values (@A)";

con.Open();


com.Transaction= con.BeginTransaction();

com.ExecuteNonQuery();

Session["con"] = com.Transaction;

Response.Redirect("default5.aspx");

and in default5.aspx I commit or rollback this transaction.

The problem is If Session expired or the page unexpectedly closed the
SqlTransaction stays in pending state.

How can I set for example a timeout for transaction or transaction
automatic closed??

thanks in advance
 
Hi all
In my web application I have following code:
SqlConnection con = new SqlConnection("Data Source=.;Connect Timeout=15;
Initial Catalog=SaamicAcc1;Integrated Security=True");

SqlCommand com = new SqlCommand("",con);


com.Parameters.AddWithValue("@A", "somevalue");

com.CommandText = "Insert into Test (Name) values (@A)";

con.Open();


com.Transaction= con.BeginTransaction();

com.ExecuteNonQuery();

Session["con"] = com.Transaction;

Response.Redirect("default5.aspx");

and in default5.aspx I commit or rollback this transaction.

The problem is If Session expired or the page unexpectedly closed the
SqlTransaction stays in pending state.

How can I set for example a timeout for transaction or transaction
automatic closed??

thanks in advance

What are you doing? You go to another page and commit the transaction
passing it in a session variable started on another page?

I'll say it to you point blank. It's not a best practice here when using
ADO.NET and SQL Server in a Web application. It's very bad programming,
and it would never pass a program walk-through by someone here on Earth.
 
in another page I have a payment and I want to after confirming payment all
changes will be saved.

Mr. Arnold said:
Hi all
In my web application I have following code:
SqlConnection con = new SqlConnection("Data Source=.;Connect Timeout=15;
Initial Catalog=SaamicAcc1;Integrated Security=True");

SqlCommand com = new SqlCommand("",con);


com.Parameters.AddWithValue("@A", "somevalue");

com.CommandText = "Insert into Test (Name) values (@A)";

con.Open();


com.Transaction= con.BeginTransaction();

com.ExecuteNonQuery();

Session["con"] = com.Transaction;

Response.Redirect("default5.aspx");

and in default5.aspx I commit or rollback this transaction.

The problem is If Session expired or the page unexpectedly closed the
SqlTransaction stays in pending state.

How can I set for example a timeout for transaction or transaction
automatic closed??

thanks in advance

What are you doing? You go to another page and commit the transaction
passing it in a session variable started on another page?

I'll say it to you point blank. It's not a best practice here when using
ADO.NET and SQL Server in a Web application. It's very bad programming,
and it would never pass a program walk-through by someone here on Earth.
 
Hi all
In my web application  I have following code:
SqlConnection con = new SqlConnection("Data Source=.;Connect Timeout=15;
Initial Catalog=SaamicAcc1;Integrated Security=True");

SqlCommand com = new SqlCommand("",con);

com.Parameters.AddWithValue("@A", "somevalue");

com.CommandText = "Insert into Test (Name) values (@A)";

con.Open();

com.Transaction= con.BeginTransaction();

com.ExecuteNonQuery();

Session["con"] = com.Transaction;

Response.Redirect("default5.aspx");

and in  default5.aspx    I commit  or rollback  this transaction.

The problem is If  Session  expired or the page unexpectedly closed the
SqlTransaction stays in pending state.

How can I set for example a timeout for transaction  or transaction
automatic closed??

thanks  in advance

Your problem is more about a poor design than about transactions..
 
in another page I have a payment and I want to after confirming payment all
changes will be saved.

You send an data object around in session with public properties that
holds the data between pages, and you persist the data in the data
object to the database using one open, transaction, commit, and close --
not sending some connection in session around to pages.
 
Back
Top