Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > SqlTransaction problem

Reply
Thread Tools

SqlTransaction problem

 
 
pers
Guest
Posts: n/a
 
      07-12-2010
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


 
Reply With Quote
 
 
 
 
Mr. Arnold
Guest
Posts: n/a
 
      07-13-2010
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.
 
Reply With Quote
 
 
 
 
pers
Guest
Posts: n/a
 
      07-13-2010
in another page I have a payment and I want to after confirming payment all
changes will be saved.

"Mr. Arnold" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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.
>



 
Reply With Quote
 
Cubaman
Guest
Posts: n/a
 
      07-13-2010
On Jul 12, 11:27*am, "pers" <(E-Mail Removed)> 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..
 
Reply With Quote
 
Mr. Arnold
Guest
Posts: n/a
 
      07-13-2010
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SQLTransaction IsolationLevel questions eric.goforth@gmail.com ASP .Net 0 06-07-2006 04:21 PM
SqlTransaction problem Neven Klofutar ASP .Net 3 11-26-2005 01:49 PM
SqlTransaction Record Not Found Joe Rigley ASP .Net 0 11-11-2005 06:31 PM
SqlTransaction issue Piotr Strycharz ASP .Net 5 12-16-2004 08:28 AM
Help! SQLTransaction and Identity(?) column in SQL Server 2K .Net Newbie ASP .Net 2 07-09-2004 09:50 AM



Advertisments