用C#写了一个定时服务,同步MYSQL与HANA的数据表,测试了一周的时间,每次都在跑了1天(每隔5分钟,每次执行过程大概在1秒内)左右的时间后就报错,抛个异常,信息如下:
执行MYSQL查询报错:System.Security.Authentication.AuthenticationException: 调用 SSPI 失败,请参见内部异常。 ---> System.ComponentModel.Win32Exception: 为验证提供的消息或签名已被更改
--- 内部异常堆栈跟踪的结尾 ---
在 System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)
在 System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
在 System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
在 System.Net.Security.SslStream.AuthenticateAsClient(String targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, Boolean checkCertificateRevocation)
在 MySql.Data.MySqlClient.NativeDriver.StartSSL()
在 MySql.Data.MySqlClient.NativeDriver.Open()
在 MySql.Data.MySqlClient.Driver.Open()
在 MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
在 MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()
在 MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
在 MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
在 MySql.Data.MySqlClient.MySqlPool.GetConnection()
在 MySql.Data.MySqlClient.MySqlConnection.Open()
在 ******.Utility.DbHelperMySQL.Query(String SQLString) 位置 D:\**\GitHub\*****\******\MySqlDbHelper.cs:行号 473
在 CentralControlService.CentralControlService.TimerEvent(Object sender, ElapsedEventArgs e) 位置 D:\**\GitHub\*****\ControlService\ControlService.cs:行号 88
程序的代码如下:
……
string connectionString = "server=127.0.0.1;port=3306;database=cc;user=newuser;password=New@123;";
……
DbHelperMySQL db = null;
……
……
public static System.Timers.Timer aTimer = null;
public ControlService()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
log2.Info("服务开始运行");
aTimer = new System.Timers.Timer();
aTimer.Elapsed += new ElapsedEventHandler(TimerEvent);
aTimer.Interval = 5 * 60 * 1000; //5分钟
aTimer.AutoReset = true;
aTimer.Enabled = true;
}
protected override void OnStop()
{
log2.Info("服务停止运行");
}
private void TimerEvent(object sender, System.Timers.ElapsedEventArgs e)
{
aTimer.Stop();
if (db == null)
{
db = new DbHelperMySQL(connectionString);
}
……
#region 同步订单
……
……
try
{
dtMysql = db.Query(sb.ToString()).Tables[0];
}
catch (Exception er)
{
log.Info("执行MYSQL查询报错:" + er.ToString());
}
……
aTimer.Start();
}
求大神帮忙看看,分析分析,先谢谢了。
问题已经处理了,主要是MySQL的连接串问题。
解决方法:
后面是发现MYSQL默认SSL连接是打开的,因为现在还不了解SSL相关设置,所以干脆就直接关闭了,我是通过config连接字符串上加上了 “ SslMode=none; ” 关闭的,目前设置后错误还未发生,顺便说下编码问题的话记得加上 “ Charset=utf8; ”