每当我的代码运行时,它都会工作,但也会崩溃。我不确定这是时间问题,还是在那之前发生了另一件事。我得到的错误代码是
起初,我以为只是我的连接被关闭了,但事实并非如此。我不确定这是我的命令文本还是什么,所有这些问题都没有帮助。
我的密码是
private void On_ProcessExit(object sender, System.EventArgs e)
{
Console.WriteLine("Server has crashed...");
_Proc.Exited -= new EventHandler(On_ProcessExit);
DB.UpdateActivePID(ServerName, 0);
if (_UserStop == true && _Proc.HasExited) {return; } //No need to restart server
else if (_UserStop == false && _Proc.HasExited) //Need to restart the server
{
Start();
}
}
public static MySqlConnection Connection
{
get
{
if(connection == null)
Open();
IsConnected();
return connection;
}
}
public static MySqlCommand PrepareCommand(string query, object[] bindings)
{
for (int i = 0; i < bindings.Length; i++)
{
var regex = new Regex(Regex.Escape("?"));
query = regex.Replace(query, "@param" + i, 1);
}
var cmd = Connection.CreateCommand();
cmd.CommandText = query;
cmd.Prepare();
int index = 0;
foreach (object o in bindings)
{
cmd.Parameters.AddWithValue("@param" + index, o);
index++;
}
return cmd;
}
public static void ExecuteUpdate(string query, params object[] bindings)
{
if (Connection == null) return;
MySqlCommand cmd = PrepareCommand(query, bindings);
Console.WriteLine("SQL Line: " + cmd.CommandText);
cmd.ExecuteNonQuery();
}
public static void UpdateActivePID(string serverName, int pid)
{
if (Connection == null) return;
string query = "UPDATE ServerParameters SET ActivePID = ? WHERE ServerName = ?";
ExecuteUpdate(query, new object[] { pid,serverName } );
}
暂无答案!
目前还没有任何答案,快来回答吧!