From: pers on 12 Jul 2010 05:27 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
From: Mr. Arnold on 13 Jul 2010 00:34 On 7/12/2010 5:27 AM, pers wrote: > 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.
From: pers on 13 Jul 2010 01:28 in another page I have a payment and I want to after confirming payment all changes will be saved. "Mr. Arnold" <Arnold(a)Arnold.com> wrote in message news:%23EL2ySkILHA.2276(a)TK2MSFTNGP06.phx.gbl... > On 7/12/2010 5:27 AM, pers wrote: >> 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. >
From: Cubaman on 13 Jul 2010 04:56 On Jul 12, 11:27 am, "pers" <reza...(a)hotmail.com> wrote: > 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..
From: Mr. Arnold on 13 Jul 2010 13:56 On 7/13/2010 1:28 AM, pers wrote: > 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.
|
Pages: 1 Prev: DataSetExample.Designer.cs Next: Custom Control in a Repeater |