我无法连接到MySQL服务器。引发异常
无法建立连接,因为目标计算机主动拒绝了它
mysql address ip
我不知道该怎么做,我没有自己使用的mysql服务器,我使用sql主机,所以我不能写命令。
我的C#代码:
Database.SQLConnection sql = new Database.SQLConnection();
if(sql.IsConnect())
{
MySqlCommand sqlcmd = new MySqlCommand("SELECT * FROM 'users' WHERE username='" + metroTextBox1.Text + "' AND password='" + metroTextBox2.Text + "' ;", sql.GetConnection());
MySqlDataReader dr = sqlcmd.ExecuteReader();
}
Ocph23
namespace Database
{
public class SQLConnection
{
public SQLConnection() { }
private string databaseName = string.Empty;
public string DatabaseName
{
get { return databaseName; }
set { databaseName = value; }
}
public string Password { get; set; }
private MySqlConnection Connection = null;
private static SQLConnection _instance = null;
public static SQLConnection Instance()
{
if (_instance == null)
_instance = new SQLConnection();
return _instance;
}
public bool IsConnect()
{
bool result = true;
if (Connection == null)
{
if (databaseName == string.Empty)
result = false;
string StrCon = string.Format("Server=x; port=3306; database=x; UID=x; password=x", databaseName);
Connection = new MySqlConnection(StrCon);
Connection.Open();
result = true;
}
return result;
}
public MySqlConnection GetConnection()
{
return Connection;
}
public void Close()
{
Connection.Close();
}
}
}
有什么问题?也许错误是在SQL服务器端?防火墙还是什么?