简体   繁体   English

MySQL查询异常在Powershell v4中使用“ 2”参数调用“填充”

[英]MySQL Query Exception calling “Fill” with “2” argument(s) from Powershell v4

Trying to execute a MySql query from Powershell ver 4, I get this error: 尝试从Powershell版本4执行MySql查询时,出现以下错误:

Could not run MySQL Query Exception calling "Fill" with "2" argument(s): "Fatal error encountered during command execution."

Here's the SQL I'm trying from Powershell. 这是我正在Powershell中尝试的SQL。 The SQL is in variable $updateReportQuery: SQL在变量$ updateReportQuery中:

$updateReportQuery = "call count_changed_mark(@count_changed_mark);"
MySQLQuery -ConnectionString $connection -query $updateReportQuery

For reference, here is a snippet from the MySQLQuery function used with other queries no problem: 供参考,这是MySQLQuery函数与其他查询一起使用没问题的代码段:

# Run MySQL Querys
Write-Verbose "Run MySQL Querys"
$command = New-Object MySql.Data.MySqlClient.MySqlCommand($query, $connection)
$dataAdapter = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($command)
$dataSet = New-Object System.Data.DataSet
$recordCount = $dataAdapter.Fill($dataSet, "data")
$dataSet.Tables["data"] | Format-Table
return $dataSet.Tables[“data”] #returns response as an object

When I output the SQL from the function to write-host then copy/paste the SQL in a SQL console, it runs fine. 当我从函数输出SQL到写入主机,然后在SQL控制台中复制/粘贴SQL时,它运行良好。 I only get the error from Powershell. 我只从Powershell中得到错误。

Thanks in advance for your help. 在此先感谢您的帮助。

Problem is with the user variable. 问题出在用户变量上。 Must add Allow User Variables=True; 必须添加Allow User Variables=True; to connection string. 连接字符串。

Example: 例:

$connection = "Server=localhost;Uid=youruserid;Pwd=yourpassword;database=yourdatabase;Allow User Variables=True;"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM