[英]Is it possible to use a MySql User Defined Variable in a .NET MySqlCommand?
[英]How can I use a MySql User Defined Variable in a .NET MySqlCommand?
我只想執行下面的Mysql語句
SET @a = 1;SELECT @a;
與 MySql.Data.MySqlClient
[System.Reflection.Assembly]::LoadWithPartialName("MySql.Data")
$password = 'mypassword'
$sql = "SET @a = 1;SELECT @a;"
$server = 'localhost'
$port = 3306
$database = 'test'
$User = 'root'
$conn=new-object MySql.Data.MySqlClient.MySqlConnection
$connectionstring = "Server=$Server;Port=$port;Database=$DataBase;Uid=$User;Pwd=$Password;allow zero datetime=yes"
$conn.ConnectionString = $connectionstring
$conn.Open()
$cmd=new-object MySql.Data.MySqlClient.MySqlCommand($sql,$conn)
$ds=New-Object system.Data.DataSet
$da=New-Object MySql.Data.MySqlClient.MySqlDataAdapter($cmd)
$da.fill($ds)
$conn.close()
$ds.tables[0]
我收到一個致命錯誤。
當我用任何一個替換 $sql 時
$sql = "SELECT DATABASE();"
或者
$sql = "SELECT 1;"
我得到了預期的結果。
我發現了這個問題,但它不能解決我的問題。
我正在嘗試將 SQLIse( SQLPSX 項目的一部分)移植到 MySQL 版本 MySQLIse。
我想處理任何簡單有效的 mysql 語句。
編輯:
我試圖運行sakila-schema.sql的部分 mysql 演示數據庫安裝腳本,它由類似的東西運行
mysql> 源 C:/temp/sakila-db/sakila-schema.sql;
我在這個博客中找到了解決方案
我必須添加
;Allow User Variables=True
到連接字符串:
$connectionstring = "Server=$Server;Port=$port;Database=$DataBase;Uid=$User;Pwd=$Password;allow zero datetime=yes;Allow User Variables=True"
作品。 我用 6.3.6.0 版本對其進行了測試。 的MySql.Data
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.