我正在pos系统上工作,一切正常。我已经在服务器资源管理器的Visual Studio中添加了MySQL数据库。
但是当我尝试通过数据库连接来连接软件时,却出现了错误:
系统无法建立连接
请向我指出我错了,什么是解决此问题的最佳方法:
private string TstServerMySQL;
private string TstPortMySQL;
private string TstUserNameMySQL;
private string TstPwdMySQL;
private string TstDBNameMySQL;
private void cmdTest_Click(object sender, EventArgs e)
{
//Test database connection
TstServerMySQL = txtServerHost.Text;
TstPortMySQL = txtPort.Text;
TstUserNameMySQL = txtUserName.Text;
TstPwdMySQL = txtPassword.Text;
TstDBNameMySQL = txtDatabase.Text;
try
{
SQLConn.conn.ConnectionString = "Server = '" + TstServerMySQL + "'; " + "Port = '" + TstPortMySQL + "';" + "user id = '" + TstUserNameMySQL + "'; " + "password = '" + TstPwdMySQL + "'; " + "Database = '" + TstDBNameMySQL + "'";
SQLConn.conn.Open();
Interaction.MsgBox("Test connection successful", MsgBoxStyle.Information, "Database Settings");
}
catch
{
Interaction.MsgBox("The system failed to establish a connection", MsgBoxStyle.Information, "Database Settings");
}
SQLConn.DisconnMy();
}