您好,每次单击按钮时都会出现此错误。我尝试在本地主机和我的remove mysql服务器上运行它。
Visual Studio错误:System.Data.sqlclient.sqlException:“建立与SQL Server的连接时发生与网络相关或特定于实例的错误。”找不到或无法访问服务器。验证实例名称是否正确,以及SQL Server是否配置为允许远程连接。(提供程序:命名管道提供程序,错误:40-无法打开与SQL Server的连接)'
我尝试将其放入mysql控制台:将movedb上的所有权限授予根@localhost,由“”标识;刷新权限;
有什么办法吗?
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();
}