リモート Mysql ベースへの connection.Open() で奇妙な例外が発生しました。このコードは正常に動作していますが、時々このエラーが発生します
コードは次のとおりです。
private static string
DatabaseServer = "",
DatabasePort = "",
DatabaseName = "",
DatabaseUserID = "",
DatabasePassword = "";
public static string ConnectionString = String.Format("SERVER={0};PORT={1};DATABASE={2};UID={3};PASSWORD={4}",
DatabaseServer, DatabasePort, DatabaseName, DatabaseUserID, DatabasePassword);
using (MySqlConnection connection = new MySqlConnection(ConnectionString))
{
try
{
if (connection != null)
{
connection.Open();
string query = @"....";
MySqlCommand cmd = new MySqlCommand(query, connection);
cmd.CommandType = CommandType.Text;
using (MySqlDataReader dataReader = cmd.ExecuteReader())
{
while (dataReader.Read())
{
}
}
}
}
catch
{}
}
問題は、 connection.Open();に来るときです。try{}catch{} であっても、アプリケーションを終了しています。
例外ログ:
System.Reflection.TargetInvocationException: An exception occurred during the operation, making the result invalid. Check InnerException for exception details. InnerException. ---> MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the specified MySQL hosts. ---> System.Exception: Call to GetHostEntry failed after 00:00:00 while querying for hostname '': SocketErrorCode=TryAgain, ErrorCode=11002, NativeErrorCode=11002. ---> System.Net.Sockets.SocketException: This is usually a temporary error during hostname resolution and means that the local server did not receive a response from an authoritative server.
в System.Net.Dns.GetAddrInfo(String name)
в System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeIPv6)
в System.Net.Dns.GetHostEntry(String hostNameOrAddress)
в MySql.Data.Common.StreamCreator.GetDnsHostEntry(String hostname)
--- ---
в MySql.Data.Common.StreamCreator.GetDnsHostEntry(String hostname)
в MySql.Data.Common.StreamCreator.GetHostEntry(String hostname)
в MySql.Data.Common.StreamCreator.GetStreamFromHost(String pipeName, String hostName, UInt32 timeout)
в MySql.Data.Common.StreamCreator.GetStream(UInt32 timeout)
в MySql.Data.MySqlClient.NativeDriver.Open()
--- ---
в MySql.Data.MySqlClient.NativeDriver.Open()
в MySql.Data.MySqlClient.Driver.Open()
в MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
в MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
в MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
в MySql.Data.MySqlClient.MySqlPool.GetConnection()
в MySql.Data.MySqlClient.MySqlConnection.Open()
в System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)
в System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)
--- ---
в System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
в System.ComponentModel.RunWorkerCompletedEventArgs.get_Result()
в Server.Engines.DonateSQL.bw_RunWorkerCompleted(Object sender, RunWorkerCompletedEventArgs e) в System.ComponentModel.BackgroundWorker.OnRunWorkerCompleted(RunWorkerCompletedEventArgs e)
в System.ComponentModel.BackgroundWorker.AsyncOperationCompleted(Object arg)
в System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
в System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
в System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
в System.Threading.ThreadPoolWorkQueue.Dispatch()
в System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
どうすればいいのかわからない。すべてを試しましたが、これが起こっているために見つけることができません。