[英]Connection failed with MySQL .NET Connector
I cannot connect to MySQL it fails on line connection.Open(), is there something wrong with my code ? 我无法连接到MySQL,但无法在线连接。Open(),我的代码有问题吗?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace MySQLConnection
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string MyConString = "SERVER=localhost:3316;" +
"DATABASE=mydb;" +
"UID=user;" +
"PASSWORD=password;";
MySqlConnection connection = new MySqlConnection(MyConString);
connection.Open();
// ...
connection.Close();
}
}
}
You need to specify the Port as a separate argument in the connection string and it looks like the password key is "Pwd" instead of "Password". 您需要在连接字符串中将端口指定为单独的参数,并且看起来密码键是“ Pwd”而不是“ Password”。
See connectionstrings.com for help on the exact syntax. 有关确切语法的帮助,请参见connectionstrings.com 。
this is the string format I use to connect via the MySql.Data.dll version 6.1.2.0 这是我用于通过MySql.Data.dll版本6.1.2.0连接的字符串格式
server={0};user id={1};password={2};database={3};port={4} 服务器= {0};用户ID = {1};密码= {2};数据库= {3};端口= {4}
so your connection string should be 所以你的连接字符串应该是
server=localhost;user id=user;password=password;database=mydb;port=3316 服务器=本地主机;用户ID =用户;密码=密码;数据库= mydb;端口= 3316
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.