[英]C# MySQL error System.Data.SqlClient.SqlException:
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.
我尝试在本地主机和删除mysql服务器上运行它。
Visual studio error:System.Data.SqlClient.SqlException: 'A network-related or instance-specific error occurred while establishing a connection to SQL Server. Visual Studio错误:System.Data.SqlClient.SqlException:'与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.
验证实例名称正确,并且已将SQL Server配置为允许远程连接。 (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)'
(提供者:命名管道提供者,错误:40-无法打开与SQL Server的连接)'
I tried putting this into mysql console:GRANT ALL PRIVILEGES On movedb TO root@localhost IDENTIFIED BY ''; 我试着把它放到mysql控制台中:将所有特权放到moveb到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();
}
You need install MySql.Data
for MySQL by Install-Package MySql.Data
您需要安装
MySql.Data
由MySQL的Install-Package MySql.Data
And use MySqlConnection
instead of SqlConnection
并使用
MySqlConnection
而不是SqlConnection
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.