SqlTransaction problem

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
 
M

Mr. Arnold

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.
 
P

pers

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.
 
C

Cubaman

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..
 
M

Mr. Arnold

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top