title: Creating a PowerShell Connection String
body: <p>I have been trying to create a ConnnectionString that will allow me to connect to my local database using PowerShell. Below is my code:</p>
  
  <pre><code>$conn = New-Object System.Data.SqlClient.SqlConnection
  $conn.ConnectionString = "Server=localhost;Database=test;Uid=&lt;username here&gt;;Pwd=&lt;password here&gt;;"
  $conn.Open()
  $sql = "SELECT EMP_STATUS FROM test_table"
  $cmd = New-Object System.Data.SqlClient.SqlCommand($sql,$conn)
  $rdr = $cmd.ExecuteReader()
  while($rdr.Read())
  {
      $test = $rdr["EMP_STATUS"].ToString()
  }
  Write-Output $test
  </code></pre>
  
  <p>However, I have NO CLUE what I am doing wrong and have been pulling my hair out for quite some time. Can anyone help me figure out what I am doing wrong in the ConnectionString?</p>
  
  <p>Thanks everyone!!</p>
  
  <hr>
  
  <p>I realized that my first problem was that I have MySQL database, not SQL database. As a result, I will have to connect using a different method. This is exactly where I need your help!! So far I have modified my code as follows: </p>
  
  <pre><code>[void][System.Reflection.Assembly]::LoadWithPartialName("MySql.Data")
  $conn = New-Object MySql.Data.MySqlClient.MySqlConnection
  
  $connString = "server=localhost;port=3306;uid=&lt;username here&gt;;pwd=&lt;password here&gt; ;database=test;"
  $conn.ConnectionString = $connString
  $conn.Open()
  $sql = "SELECT EMP_STATUS FROM test_table"
  $cmd = New-Object MySql.Data.MySqlClient.MySqlCommand($sql,$conn)
  $rdr = $cmd.ExecuteReader()
  $test = @()
  while($rdr.Read())
  {
      $test += ($rdr["EMP_STATUS"].ToString())
  }
  Write-Output $test
  </code></pre>
  
  <p>However, here are a few more questions: 
  1) How do you use the MySQL .NET connection tool to connect to a local MySQL database?
  2) Where should this PowerShell script be saved?
  3) Are there any additional changes I should make?</p>
  
  <p>Thanks so much</p>