我无法从我的 C# windows 窗体应用程序连接到 MySql。我也已经在 无效的用户名/密码中发布了一个问题
但没有任何解决方案。假设我的网站名称是 www.google.com,cpanel 用户名是 imrancpanel,我的 cpanel 密码是 imranpd,我创建一个数据库 imrandb,创建一个数据库用户 imrandbuser 并检查该用户对该网站的所有权限。这段代码有什么问题?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace CSharpMySql
{
class Program
{
static string getString(string msg)
{
Console.Write(msg);
return Console.ReadLine();
}
static void Main(string[] args)
{
string myConnectionString = @"server=google.com;userid=imrancpanel_imrandbuser;
password=imranpd;database=imrandb";
MySqlConnection con = null;
MySqlDataReader reader = null;
string cretablestr = "CREATE TABLE IF NOT EXISTS AutoCaptchaTable (LoginID char(25), Password char(25), ActivationStatus char(25), NofTransactions int );"
try
{
//MySqlConnection
conn = new MySqlConnection(myConnectionString);
conn.Open();
MessageBox.Show("OK");
conn.Close();
}
catch (MySqlException ex)
{
switch (ex.Number)
{
case 0:
MessageBox.Show("Cannot connect to server. Contact administrator");
break;
case 1042:
MessageBox.Show("Can't get hostname address. Check your internet connection. If does not solve, contact Administrator");
break;
case 1045:
MessageBox.Show("Invalid username/password");
break;
}
}
}
}
}