因为公司有个项目需要连接第三方的MySQL数据库进行一些查询操作,我对MySQL不是非常了解,所以我就先写了个Demo想试试看能否正常连接MySQL,结果就出现这个问题,上百度查了之后好像是说因为mysql8数据库版本问题,我也没看明白,但是按照他们的解决方案还是没有解决,所以希望哪位对这一块比较了解的,能够帮忙告知一下,谢谢
解决方案 »
- 如何向DATATABLE添加一列HypeoLinkEdit?
- 下载文件时,出现服务器提交了协议冲突. Section=ResponseHeader Detail=CR 后面必须是 LF
- winform播放视频的问题
- wpf中复杂的storyboard怎么用代码写?
- 为什么我的Matlab里面没有MWArray.dll
- c#生成excel表格时,在保存文件时出现“无法访问文件。请尝试下列方法之一”的错误!!
- 程序集的签名疑惑,用了公钥,没有证书,怎么知道这是谁出的程序集呢?
- c#选中文件夹控件 怕分浪费了回帖有一定建议的狂补分
- c# 打开excel提示System.Runtime.InteropServices.COMException
- 有關網頁抓取資料 - 登入問題 c# winform
- c# 海康卫视车牌识别
- 求告各位大神如何用c# 实现一个数据填报的程序,我说做java的,而且还是一名不算入行的新手小菜鸟
哪位兄台给我提供一个靠谱的解决方案,谢谢了
另外,我用的是.net2.0
public class MySqlHelper
{
public string DBIpAddress
{
get;
set;
} public string DatabaseName
{
get;
set;
} public string UserName
{
get;
set;
} public string Password
{
get;
set;
} public int Port
{
get;
set;
} private string connStr = null; public MySqlHelper(string dbIpAddr, string dbName, string userName, string password,int port)
{
this.DBIpAddress = dbIpAddr;
this.DatabaseName = dbName;
this.UserName = userName;
this.Password = password;
this.Port = port; this.BuildConnStr();
} private void BuildConnStr()
{
this.connStr = String.Format("Database='{0}';Data Source='{1}';User Id='{2}';Password='{3}';charset='utf8';pooling=true;port='{4}'",
this.DatabaseName, this.DBIpAddress, this.UserName, this.Password,this.Port);
} public int ExUpdate(string sql, MySqlParameter[] param)
{
try
{
using (var conn = new MySqlConnection(this.connStr))
{
MySqlCommand cmd = new MySqlCommand(sql, conn);
if (param != null)
{
cmd.Parameters.AddRange(param);
}
conn.Open();
int result = cmd.ExecuteNonQuery();
return result;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
return -1;
} public DataSet ExSelect(string sql, MySqlParameter[] param)
{
using (var conn = new MySqlConnection(this.connStr))
{
try
{
DataSet ds = new DataSet();
MySqlCommand cmd = new MySqlCommand(sql, conn);
if (param != null)
{
cmd.Parameters.AddRange(param);
}
MySqlDataAdapter sda = new MySqlDataAdapter(cmd);
sda.Fill(ds);
return ds; }
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
return null;
}
}
}