problem with connections not being releases and strange mysql error (MySqlException: Sort Aborted)

Last post 04-05-2008 7:25 AM by aram. 5 replies.

Sort Posts:

  • problem with connections not being releases and strange mysql error (MySqlException: Sort Aborted)

    04-02-2008, 2:51 AM
    • All-Star
      23,809 point All-Star
    • pkellner
    • Member since 11-12-2004, 10:42 AM
    • San Jose, California
    • Posts 3,576
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs

     for some reason, my query's connection is crashing some of the time and then the connection is not freed.  I'm using the odbc driver (mysql.data.dll).

     I open the connection with using so I was thinking it should always automatically close.

     any thoughts?

     

    <add name="OTRSConnection" connectionString="server=localhost ; username=peter; password=xxxx; database=OTRS; pooling=false"

    providerName="System.Data.Odbc" />

     

    using (MySqlConnection conn = new MySqlConnection(connectString))

    { // 27 is stateupdate

    conn.Open();

    string sqlSelect = String.Format(

    @"

    SELECT ...

    MySqlCommand cmd = new MySqlCommand(sqlSelect, conn);

    cmd.Parameters.Add("?startDate", MySqlDbType.Datetime).Value = startDate;

    cmd.Parameters.Add("?endDate", MySqlDbType.Datetime).Value = endDate;using (MySqlDataReader reader = cmd.ExecuteReader())

    {

    try

    {

    while (reader.Read())

    {

    string ticketDateString = reader.IsDBNull(0) ? string.Empty : reader.GetString(0);

    DateTime ticketDate = Convert.ToDateTime(ticketDateString);

    int userId = reader.IsDBNull(1) ? -1 : reader.GetInt32(1);

    int totalTickets = reader.IsDBNull(2) ? 0 : reader.GetInt32(2);

    Ticket ticket = new Ticket(totalTickets, ticketDate, userId,string.Empty);

    listTicket.Add(ticket);

    }

    }

    catch (Exception ee)

    {

    throw new ApplicationException(ee.ToString());

    }

    }

    }

    Peter Kellner
    http://peterkellner.net
    Microsoft MVP • ASPInsider
  • Re: problem with connections not being releases and strange mysql error (MySqlException: Sort Aborted)

    04-02-2008, 2:59 AM
    • Contributor
      2,161 point Contributor
    • Avinash Desai
    • Member since 01-23-2008, 9:24 AM
    • Bangalore-INDIA
    • Posts 719

     Hi

    It doesnt close the connection automatically you have to close the connection

    conn.Close();

     

    I have also used mysql with odbc its fine

     

    Thanks
    ~Avinash desai~
    Software Developer
    Bangalore

    Please remember to click "Mark as Answer" on this post if it helped you.
  • Re: problem with connections not being releases and strange mysql error (MySqlException: Sort Aborted)

    04-02-2008, 3:42 AM
    • All-Star
      23,809 point All-Star
    • pkellner
    • Member since 11-12-2004, 10:42 AM
    • San Jose, California
    • Posts 3,576
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs

    are you implying that the using clause for mysqlconnection is not implemented properly and does not automatically close the connection? that would be hard to believe.

    Peter Kellner
    http://peterkellner.net
    Microsoft MVP • ASPInsider
  • Re: problem with connections not being releases and strange mysql error (MySqlException: Sort Aborted)

    04-03-2008, 4:15 PM
    • Member
      231 point Member
    • aram
    • Member since 04-03-2008, 3:51 PM
    • Cyprus
    • Posts 52

    Hello,

    Have you tried closing the reader after your while clause is closed?

     

    while (reader.Read()) 
    {
    
    string ticketDateString = reader.IsDBNull(0) ? string.Empty : reader.GetString(0); 
    DateTime ticketDate = Convert.ToDateTime(ticketDateString);
    
    int userId = reader.IsDBNull(1) ? -1 : reader.GetInt32(1); 
    int totalTickets = reader.IsDBNull(2) ? 0 : reader.GetInt32(2);
    
    Ticket ticket = new Ticket(totalTickets, ticketDate, userId,string.Empty); 
    listTicket.Add(ticket);
    
    }
    
    reader.close()

     or you may want to try to pur reader.close in a 'finaly' clause of your 'try catch' .

    There is a difference between disposing the reader and closing it. And I'm also guessing you have to close the connection after you close the reader. Otherwise you would get the error indicating that it is in use by a reader.

    May be that is what causing the trouble.

    Regards,

     

    Aram Azhari
  • Re: problem with connections not being releases and strange mysql error (MySqlException: Sort Aborted)

    04-04-2008, 8:54 AM
    • All-Star
      23,809 point All-Star
    • pkellner
    • Member since 11-12-2004, 10:42 AM
    • San Jose, California
    • Posts 3,576
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs

    So, I left out a couple lines of code that showed I am opening the reader with the using syntax so just like mysqlconnection, dispose is being called.

    What is the difference between closing the reader and calling dispose?

    Peter Kellner
    http://peterkellner.net
    Microsoft MVP • ASPInsider
  • Re: problem with connections not being releases and strange mysql error (MySqlException: Sort Aborted)

    04-05-2008, 7:25 AM
    • Member
      231 point Member
    • aram
    • Member since 04-03-2008, 3:51 PM
    • Cyprus
    • Posts 52

    A disposed reader cannot be used after disposal unless you rewrite the line to create a new object from it the line: reader= new datareader();

    But if you close the reader, you can open it again anytime without requiring to create the reader object again.

    for ex.

    reader.close()

    reader= yoursqlcommand.executereader();

     

    Aram Azhari
Page 1 of 1 (6 items)