使用MySQLDriverCS完成
引用MySQLDriverCS
正文关键代码:
using MySQLDriverCS;
public static int DeleteHy()
{
int result = 0;
string sql = string.Format("delete from OutInfo where id<={0}", Service.HYID);
MySQLConnection conn = new MySQLConnection("Data Source=数据库名称;Password=**;User ID=info;Location=124.232.156.144;Port=8851;");
try
{
MySQLCommand cmd = new MySQLCommand(sql, conn);
result = cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
CommonTools.WriteLog(ex.Message, "Service.cs", "GetHy");
}
finally
{
conn.Close();
conn.Dispose();
}
return result;
}
这里需要注意的一个地方是必须要conn.Dispose();
否则你的连接数会不停的涨上去,直到MySQL可连接数溢出.然后挂掉,要重启,所以切记要dispose