How can I use a MySql User Defined Variable in a .NET MySqlCommand?
I simply want to execute the following Mysql statement
SET @a = 1;SELECT @a;
with 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]
I get a fatal error.
When I replace $sql by either
$sql = "SELECT DATABASE();"
or
$sql = "SELECT 1;"
I get the expected result.
I found this question, but it doesn't solve my problem.
I'm trying to port SQLIse (a part of the SQLPSX project ) to the MySQL version MySQLIse.
I want to process any simple valid mysql statements.
EDIT:
I was trying to run parts of the sakila-schema.sql the mysql demo database install script which runs by something like
mysql> SOURCE C:/temp/sakila-db/sakila-schema.sql;
I found the solution in this blog
I have to add
;Allow User Variables=True
to the connection string:
$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
.
ReferenceURL : https://stackoverflow.com/questions/5524632/how-can-i-use-a-mysql-user-defined-variable-in-a-net-mysqlcommand
'IT' 카테고리의 다른 글
텍스트 열을 고유 키로 만들기 (0) | 2023.10.30 |
---|---|
풀 후 이전 버전과 변경된 파일을 어떻게 다릅니까? (0) | 2023.10.30 |
jQuery에서 특정 폼 요소를 선택하는 방법은? (0) | 2023.10.30 |
WooCommerce 아카이브 페이지의 상품 제목 아래에 사용자 정의 필드 값 추가 (0) | 2023.10.30 |
mysql에서 방금 삭제된 행을 복구하는 방법? (0) | 2023.10.30 |