title: How can I connect to a local MySQL database using System.Data.SqlClient.SqlConnection? Using C# .Net 4.6.1
body: <p>I'm designing a WPF form that needs to connect to a local MySQL database. I've installed mysql on my local machine and created a database, with a username and password to connect to it. See two screenshots below for more information.</p>
  
  <p><a href="https://i.stack.imgur.com/06dbt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/06dbt.png" alt="Screenshot from within MySQL Workbench"></a></p>
  
  <p><a href="https://i.stack.imgur.com/l0WRW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l0WRW.png" alt="Connecting to the database through MySQL Workbench"></a></p>
  
  <p>My code currently looks like this:</p>
  
  <pre><code>    public static bool InitialConnection()
      {
          try
          {
              using (SqlConnection con = new SqlConnection())
              {
                  con.ConnectionString = "Server=127.0.0.1;Database=StudentTravelPlannerDB;Uid=STPUser;Pwd=CORRECT_PASSWORD;";
                  con.Open();
              }
              return true;
          }
          catch
          {
              return false;
          }
      }
  </code></pre>
  
  <p>However, when I run my WPF form, which calls this function, it always freezes for a few seconds, and the above function will return false.</p>
  
  <p>Removing the try/catch statements, the application fails and gives me an error pointing to the 'con.Open()' line, stating:</p>
  
  <p>"An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll</p>
  
  <p>Additional information: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"</p>
  
  <hr>
  
  <p>So what could be the problem here? My password is definitely correct. I think I laid out the connection string right, and I've tried different variants and it's always the same response, adding the port doesn't help either. </p>
  
  <p>Any guidance or solutions appreciated, thank you. </p>