MySQL Query Exception使用Powershell v4中的“2”参数调用“Fill”

时间:2016-02-13 13:37:44

标签: mysql powershell

尝试从Powershell ver 4执行MySql查询,我收到此错误:

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

这是我从Powershell尝试的SQL。 SQL位于变量$ updateReportQuery:

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

供参考,这里是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

当我将SQL从函数输出到write-host然后在SQL控制台中复制/粘贴SQL时,它运行正常。我只收到Powershell的错误。

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

问题在于用户变量。必须将Allow User Variables=True;添加到连接字符串。

示例:

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