0

Hello i get this error every time when i click on button. I tried running it on both local host and my remove mysql server.

Visual studio error:System.Data.SqlClient.SqlException: '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)'

I tried putting this into mysql console:GRANT ALL PRIVILEGES On movedb TO root@localhost IDENTIFIED BY ''; FLUSH PRIVILEGES; Any ideas what do do with it?

private void button1_Click(object sender, EventArgs e)
    {
        SqlConnection cn = new SqlConnection("Server=localhost;Database=movedb;Uid=root;Pwd=;");
        SqlCommand cmd = new SqlCommand("SELECT usertype FROM table1", cn);
        cmd.Parameters.AddWithValue("usertype", usertype.Text);
        cn.Open();
        string usertype123= cmd.ExecuteScalar()?.ToString();


        if (usertype123 == "admin")
            MessageBox.Show("yes");
        else
            MessageBox.Show("You can't access this part of the program.  For questions call 867-5309.");


        cn.Close();
    }

1 Answers1

4

You need install MySql.Data for MySQL by Install-Package MySql.Data

And use MySqlConnection instead of SqlConnection

Refer How to connect to MySQL Database?

Hien Nguyen
  • 24,551
  • 7
  • 52
  • 62