我使用的是帶有mysqlConnector的Visual Studio 2010(C#),一切看起來都很好。 但是,當我嘗試從服務器請求某些東西時,出現此錯誤:已經有一個開放的DataReader與此連接相關聯,必須先關閉
「已經有一個與此連接關聯的打開的DataReader,必須先關閉它。」
這是我的代碼:
gc.connect();
List<Conseiller> conseillers = gc.getAllConseillers();
--
public void connect()
{
string connStr = "SERVER=localhost;UID=root;DATABASE=Projet;Password=root";
oConn = new MySqlConnection(connStr);
try
{
oConn.Open();
Console.WriteLine("Successfully connected to the data base");
}
catch (OdbcException caugth)
{
/* Traitement de l'erreur */
Console.WriteLine(caugth.Message);
}
}
--
public List<Conseiller> getAllConseillers()
{
MySqlCommand oComm = oConn.CreateCommand();
oComm = oConn.CreateCommand();
Console.WriteLine("SELECT * FROM conseillers");
oComm.CommandText = "SELECT * FROM conseillers";
MySqlDataReader oReader = oComm.ExecuteReader(); // Error here
}
我哪裏錯了?
[例外:已經有與此連接相關聯的打開的DataReader必須首先關閉]的可能重複(http://stackoverflow.com/questions/5440168/exception-there-is -already-AN-開放的DataReader相關與 - 此連接-w)的 – BartoszKP 2014-08-02 11:12:29