我尝试使用MySQLConnector通过phpAdmin连接虚拟服务器上的mysql数据库。我使用不同的登录来检查密码和IP是否正确,并在视图尝试后得到
错误:
代码:
static string server = "999.999.999.20";
static string database = "admin_";
static string user = "root";
static string pswd = "secret";
public static void login()
{
string connectionString = "Server = " + server + ";database = "
+ database + ";uid = " + user + ";password = " + pswd + ";"
+"SslMode=None;";
using (MySqlConnection connection = new MySqlConnection(connectionString))
{
connection.Open();
在“Connection.Open();”处抛出异常。连接字符串似乎正确,因为当我删除SSL模式或其他东西时,我得到特定的异常。我使用Recerense到MySql.Data.RT
我的问题是:
Exception意味着什么,或者我应该在服务器上指定什么?
答案 0 :(得分:1)
我认为这与您的操作系统文化有关,并假设mysql连接器正在设置引用操作系统文化的编码。请将编码指令添加到您的连接字符串中,如下所示;
static string server = "999.999.999.20";
static string database = "admin_";
static string user = "root";
static string pswd = "secret";
public static void login()
{
string connectionString = "Server = " + server + ";database = "
+ database + ";uid = " + user + ";password = " + pswd + ";"
+"SslMode=None;"
+"CharSet=utf8;";
using (MySqlConnection connection = new MySqlConnection(connectionString))
{
connection.Open();
PS:数据库上的编码很重要,我假设你使用的是UTF8