gpt4 book ai didi

c# - MySqlConnection.StateChange 永远不会获取

转载 作者:行者123 更新时间:2023-11-29 13:59:17 25 4
gpt4 key购买 nike

MySqlConnection.StateChange 是如何工作的?

我有以下代码。

conn.StateChange += ConnectionStateChanged;

private void ConnectionStateChanged(Object sender, StateChangeEventArgs e) {
switch (e.CurrentState) {
// is never equal to Fetching
}
}

public DataTable Query(string query) {
DataTable dt = new DataTable();

using (MySqlDataAdapter a = new MySqlDataAdapter(query, conn)) {
try {
a.SelectCommand.CommandTimeout = 5;
a.Fill(dt);
} catch {
return null;
}
}

return dt;
}

为什么 ConnectionStateChanged 永远不会通过 ConnectionState.Fetching 或 ConnectionState.Executing 调用?

最佳答案

好吧,我可能会误解msdn ,但这些状态似乎没有实现(枚举值只是“保留”,即使在 .net 4.5 中也是如此):

Executing The connection object is executing a command. (This value is reserved for future versions of the product.)

Fetching The connection object is retrieving data. (This value is reserved for future versions of the product.)

关于c# - MySqlConnection.StateChange 永远不会获取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15339273/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com