title: How can I use a MySql User Defined Variable in a .NET MySqlCommand?
body: <p>I simply want to execute the following Mysql statement </p>
  
  <pre><code>SET @a = 1;SELECT @a;
  </code></pre>
  
  <p>with  MySql.Data.MySqlClient</p>
  
  <pre><code>[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]
  </code></pre>
  
  <p>I get a fatal error.</p>
  
  <p>When I replace $sql by either</p>
  
  <pre><code>$sql = "SELECT DATABASE();"
  </code></pre>
  
  <p>or</p>
  
  <pre><code>$sql = "SELECT 1;"
  </code></pre>
  
  <p>I get the expected result.</p>
  
  <p>I found this <a href="https://stackoverflow.com/questions/958953/is-it-possible-to-use-a-mysql-user-defined-variable-in-a-net-mysqlcommand">question</a>, but it doesn't solve my problem.</p>
  
  <p>I'm trying to port SQLIse (a part of the <a href="http://sqlpsx.codeplex.com/" rel="noreferrer">SQLPSX project</a> ) to the MySQL version MySQLIse.</p>
  
  <p>I want to process any simple valid mysql statements.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I was trying to run parts of the <a href="http://dev.mysql.com/doc/sakila/en/sakila.html" rel="noreferrer">sakila-schema.sql</a> the mysql demo database install script which runs by something like</p>
  
  <blockquote>
    <p>mysql> SOURCE
    C:/temp/sakila-db/sakila-schema.sql;</p>
  </blockquote>