INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How to reuse Cursor Number? - C# / Gupta sqlbase 9

How to reuse Cursor Number? - C# / Gupta sqlbase 9

(OP)
I know I could handle this with a large sql command or SQL procedure, but I want to make a more robust process that can accurately report progress and support cancellation.

Unless I close the 2nd sqlbase connection after each row read from the first connection, it will assign a new cursor for the query within while(reader.read()) loop.
I've handled this in the code below, but disconnecting doesn't seem the right way to handle this.

Any tips?

CODE

     private void dostuff()
        {
            bool bError = false;
            string sErrorMessages = "";
            int iCount = 0;
            int iTotal = 18000; //test value
            string sID = "";
            string sDts = "";
            string sGetID = "select id, DTS from tableA";
            string sGetMinDTS = "select min(DTS) from TableB where id = ";
            OleDbConnection conn1 = new OleDbConnection("Provider=SQLBaseOLEDB;Data Source=DBNAME;User ID=admin;Password=myPass;");
            OleDbConnection conn2 = new OleDbConnection("Provider=SQLBaseOLEDB;Data Source=DBNAME;User ID=admin;Password=myPass;");
            conn1.Open();

            try
            {
                OleDbCommand commit = new OleDbCommand("commit", conn2);
                OleDbCommand comGetID = new OleDbCommand(sGetID, conn1);


                OleDbDataReader reader = comGetID.ExecuteReader();

                while (reader.Read())
                {

                    progressBar1.Value = Convert.ToInt32(iCount * (100.0 / iTotal));
                    iCount++;

                    sID = reader[0].ToString();
                    sDts = reader[1].ToString();

                    OleDbCommand comGetMinID = new OleDbCommand(sGetMinDTS + sID, conn2);
                    OleDbDataReader reader2 = comGetMinID.ExecuteReader();
                    conn2.Open();
                    while (reader2.Read())
                    {
                        if (reader2[0].ToString().Length > 0)
                        {
                            if (Convert.ToDateTime(reader2[0].ToString()) < Convert.ToDateTime(sDts))
                            {
                                OleDbCommand upd = new OleDbCommand("update tableB set dts = " + reader2[0] + "where id = '" + sID + "'", conn2);
                                upd.ExecuteNonQuery();
                            }
                        }
                    
                    }
                    conn2.Close();

                }
            }
            catch (OleDbException e)
            {

                sErrorMessages = "";
                for (int i = 0; i < e.Errors.Count; i++)
                {
                    sErrorMessages +=
                                     "ErrCount# " + (i + 1) + "\n" +
                                     "Message: " + e.Errors[i].Message + "\n" +
                                     "NativeError: " + e.Errors[i].NativeError + "\n" +
                                     "Source: " + e.Errors[i].Source + "\n" +
                                     "SQLState: " + e.Errors[i].SQLState + "\n\n" + sGetID
                    ;
                    bError = true;
                }
            }
        }

 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close