c# - Powershell Mysql 错误

标签 c# mysql powershell

这段代码是:

$cm = New-Object -TypeName MySql.Data.MySqlClient.MySqlCommand
$sql = "Select * FROM onaylanan Order by onaylanma_id ASC"
$cm.Connection = $Connection
$cm.CommandText = $sql
$dr = $cm.ExecuteReader()

while ($dr.Read())
{
$cm2 = New-Object -TypeName MySql.Data.MySqlClient.MySqlCommand
$sql2 = "Delete FROM onaylanan Where onaylanma_id=4"
$cm2.Connection = $Connection
$cm2.CommandText = $sql2
$dr2 = $cm2.ExecuteNonQuery()
  $dr2.Close();

}
$dr.Close();
$Connection.Close()

这个错误是:

Exception calling "ExecuteNonQuery" with "0" argument(s): "There is already an open DataReader associated with this Connection which must be closed first."

最佳答案

如错误所示,您不能通过同一连接同时执行两个查询。

打开第二个连接(您可以将其命名为 Connection2)并将其分配给 $cm2:

$cm2.Connection = $Connection2

关于c# - Powershell Mysql 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48932539/

相关文章:

java - 配置 Tomcat 以便我可以将 JSP 页面连接到 MySQL

mysql - 查询被屏蔽的用户

powershell - 查找文件/文件夹的修改日期

c# - 直接通过C#中的实例连接

c# - 什么相当于 Visual Studio Code VSCode 中的 TAB +TAB

mysql - 外键 - 执行表

powershell - PowerShell-Get-Credential解码密码?

powershell - 在Powershell中使用UFormat转换时为什么会出现语法错误

c# - 在 C# 或 python 上写入 COM 端口

c# - 是否有一种类型的对象,我可以将 Buttons 和 MenuItem 对象都转换到该对象以访问它们的 Tag 属性?