1 Replies - 1578 Views - Last Post: 18 August 2012 - 05:19 AM Rate Topic: -----

#1 siddu1281  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 17-August 12

Error related to execute reader

Posted 17 August 2012 - 02:38 AM

iam getting error in an web application .the error is as follows

ExecuteReader requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: ExecuteReader requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized.


private void Save(string tablename)
    {
        con.Open();

        string sql = string.Format("select * from {0}", tablename);

        SqlCommand cmd = this.con.CreateCommand();
        cmd.CommandText = string.Format("Select * from {0}", tablename);
       
        SqlTransaction trans = this.con.BeginTransaction();

        SqlDataAdapter da = new SqlDataAdapter(sql, con);
        new SqlCommandBuilder(da);
       


        da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
        da.AcceptChangesDuringUpdate = true;
       
        da.Update(ds.Tables[tablename]);
        trans.Commit();
        con.Close();
    }





thanks
regards
siddartha

Is This A Good Question/Topic? 0
  • +

Replies To: Error related to execute reader

#2 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 444
  • View blog
  • Posts: 1,492
  • Joined: 28-April 09

Re: Error related to execute reader

Posted 18 August 2012 - 05:19 AM

Here's the MSDN page for the SqlTransaction class. It has an example of how to use it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1