Groups > Databases > MySQL for ASP.NET > Re: problem with connections not being releases and strange mysql error (MySqlException: Sort Aborted)




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

problem with connections not being releases and strange mysql error (MySqlException: Sort Aborted)
Wed, 2 Apr 2008 09:51:47 +0000
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?

 

<addname="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 =
newTicket(totalTickets, ticketDate, userId,string.Empty);

listTicket.Add(ticket);

}

}catch (Exception ee)

{thrownewApplicationException(ee.ToString());

}

}

}
Post Reply
Re: problem with connections not being releases and strange mysql error (MySqlException: Sort Aborted)
Wed, 2 Apr 2008 09:59:35 +0000
Hi

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

conn.Close();

 

I have also used mysql with odbc its fine
Post Reply
Re: problem with connections not being releases and strange mysql error (MySqlException: Sort Aborted)
Wed, 2 Apr 2008 10:42:39 +0000
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.
Post Reply
Re: problem with connections not being releases and strange mysql error (MySqlException: Sort Aborted)
Thu, 3 Apr 2008 23:15:57 +0000
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,
Post Reply
about | contact