我尝试连接到我 friend 创建的服务器上的 MySQL 数据库,但它仍然说无法连接到服务器!
这是我的代码:
String connectionString = "Persist Security Info=False;database=qwertyui;server=www.qwertyuiop.com;Uid=asdfghj;Pwd=qazwsxedc;Connect Timeout=30";
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand("INSERT INTO etc.... ");
cmd.CommandType = CommandType.Text;
cmd.Connection = connection;
cmd.Parameters.AddWithValue( etc.... );
connection.Open();
int r = cmd.ExecuteNonQuery();
}
它在 connection.Open()
指令上失败并抛出异常 -> 无法连接到服务器。
有什么想法吗?
最佳答案
SqlConnection
是一个 SQL Server 客户端。
您需要从 NuGet 下载 MySql 客户端。
关于c# - 使用 C# 连接到 MySQL Web 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17798029/