Menu
  • HOME
  • TAGS

c# mysqlreader multithread fail

c#,multithreading,database-connection,mysqldatareader

Note that MySqlConnection instance is not guaranteed to be thread safe. You should avoid using the same MySqlConnection in several threads at the same time. It is recommended to open a new connection per thread and to close it when the work is done. Actually, connections will not be created/disposed...

declaring a MySqlDataReader without initialising it

c#,mysqldatareader

Just assign it with null. The compiler will know a value has assigned, although it is null. MySqlDataReader rdr = null; In your finally block, check on the null value. MySqlDataReader rdr = null; try { ... // do stuff here } finally { if (rdr != null) { //...

C# DataReader error

c#,mysqldatareader

Change the getConnection function public static MySqlConnection getConnection() { MySqlConnection connect = null; try { connect = new MySqlConnection(connect); connect.Open(); return connect; } catch (MySqlException e) { throw new Exception("Cannot connect", e); } } let all the other codes as it is...