SqlTransaction problem

Discussion in 'ASP .Net' started by pers, Jul 12, 2010.

  1. pers

    pers Guest

    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
    pers, Jul 12, 2010
    #1
    1. Advertising

  2. pers

    Mr. Arnold Guest

    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.
    Mr. Arnold, Jul 13, 2010
    #2
    1. Advertising

  3. pers

    pers Guest

    in another page I have a payment and I want to after confirming payment all
    changes will be saved.

    "Mr. Arnold" <> wrote in message
    news:%...
    > 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.
    >
    pers, Jul 13, 2010
    #3
  4. pers

    Cubaman Guest

    On Jul 12, 11: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


    Your problem is more about a poor design than about transactions..
    Cubaman, Jul 13, 2010
    #4
  5. pers

    Mr. Arnold Guest

    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.
    Mr. Arnold, Jul 13, 2010
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. .Net Newbie
    Replies:
    2
    Views:
    694
    =?Utf-8?B?RGVlcA==?=
    Jul 9, 2004
  2. Piotr Strycharz

    SqlTransaction issue

    Piotr Strycharz, Dec 15, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    579
    Piotr Strycharz
    Dec 16, 2004
  3. Joe Rigley

    SqlTransaction Record Not Found

    Joe Rigley, Nov 11, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    369
    Joe Rigley
    Nov 11, 2005
  4. Neven Klofutar

    SqlTransaction problem

    Neven Klofutar, Nov 23, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    515
  5. Replies:
    0
    Views:
    1,644
Loading...

Share This Page