我如何使用MySQL用户在.NET的MySqlCommand定义的变量?如何使用、变量、定义、用户

由网友(你真的好假)分享简介:我只是想执行下面的MySQL语句设置@a = 1; SELECT @a;与MySql.Data.MySqlClient [System.Reflection.Assembly] :: LoadWithPartialName(MySql.Data)$密码='输入mypassword'$ SQL =设置@a = 1; SE...

我只是想执行下面的MySQL语句

 设置@a = 1; SELECT @a;
 

与MySql.Data.MySqlClient

  [System.Reflection.Assembly] :: LoadWithPartialName(MySql.Data)

$密码='输入mypassword'

$ SQL =设置@a = 1; SELECT @a;

$服务器='localhost'的
$端口= 3306
$数据库=测试
$ USER ='根'


$康恩=新的对象MySql.Data.MySqlClient.MySqlConnection
$的ConnectionString =服务器= $服务器,端口= $端口;数据库= $数据库; UID = $用户; PWD = $密码;允许以零日期时间= YES
$ conn.ConnectionString = $的ConnectionString
$ conn.Open()

$ CMD =新的对象MySql.Data.MySqlClient.MySqlCommand($的SQL,$康恩)
$ DS =新对象System.Data.DataSet中
$ DA =新对象MySql.Data.MySqlClient.MySqlDataAdapter($ CMD)
$ da.fill($ DS)
$ conn.close()
$ ds.tables [0]
 

我得到一个致命的错误。

mysql5.7闪退 MySQL 5.7 Command Line Client输入密码后闪退和windows下mysql忘记root密码的解决办法...

当我更换$ SQL由两种

  $ SQL =SELECT DATABASE();
 

  $ SQL =SELECT 1;
 

我得到预期的结果。

我发现这个question,但它并没有解决我的问题。

我想端口SQLIse(的 SQLPSX项目的一部分)的MySQL版本MySQLIse。

我要处理什么简单有效的MySQL语句。

编辑:

我试图运行的Sakila-schema.sql文件的部分 mysql的演示数据库安装的运行由像

脚本   

MySQL的SOURCE   C:/temp/sakila-db/sakila-schema.sql;

解决方案

我发现这个bolg

我要补充

 ;允许用户变量=真
 

在连接字符串

  $的ConnectionString =服务器= $服务器,端口= $端口;数据库= $数据库; UID = $用户; PWD = $密码;允许以零日期时间= YES,允许用户变量= TRUE
 

工作。我与6.3.6.0版本进行了测试。的MySql.Data。

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 bolg

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"

works. I tested it with version 6.3.6.0. of MySql.Data.

阅读全文

相关推荐

最新文章