none
Rollbacks in My Game server RRS feed

  • Question

  • Hi... I have a command.ExecuteNonQuery(); problem in my code

     

     

    public static void SaveChar(Character Charr)

    {

    try

    {

    Charr.PackInventory();

    Charr.PackEquips();

    Charr.PackSkills();

    Charr.PackProfs();

    Charr.PackWarehouses();

    Charr.PackEnemies();

    Charr.PackFriends();

    MySqlCommand Command = null;

    Command = new MySqlCommand("UPDATE `Characters` SET `CharName` = '" + Charr.Name + "', `Level` = " + Charr.Level + ",`Exp` = " + Charr.Exp + ",`GuildDonation` = " + Charr.GuildDonation + ",`Strength` = " + Charr.Str + ",`Agility` = " + Charr.Agi + ",`Vitality` = " + Charr.Vit + ",`Spirit` = " + Charr.Spi + ",`Job` = " + Charr.Job + ",`Model` = " + Charr.Model + ",`Money` = " + Charr.Silvers + ",`CPs` = " + Charr.CPs + ",`CurrentHP` = " + Charr.CurHP + ",`CurrentMP` = " + Charr.CurMP + ",`StatPoints` = " + Charr.StatP + ",`MyGuild` = " + Charr.GuildID + ",`GuildPos` = " + Charr.GuildPosition + ",`LocationMap` = " + Charr.LocMap + ",`LocationX` = " + Charr.LocX + ",`LocationY` = " + Charr.LocY + ",`Hair` = " + Charr.Hair + ",`Equipment` = '" + Charr.PackedEquips + "',`Inventory` = '" + Charr.PackedInventory + "',`PKPoints` = " + Charr.PKPoints + ",`PrevMap` = " + Charr.PrevMap + ", `Skills` = '" + Charr.PackedSkills + "', `Profs` = '" + Charr.PackedProfs + "',`RBCount` = " + Charr.RBCount + ",`Avatar` = " + Charr.Avatar + ",`WHMoney` = " + Charr.WHSilvers + ",`VP` = " + Charr.VP + ",`Warehouses` = '" + Charr.PackedWHs + "',`Friends` = '" + Charr.PackedFriends + "',`dexp` = '" + Charr.dexp + "',`dexptime` = '" + Charr.dexptime + "',`Enemies` = '" + Charr.PackedEnemies + "' WHERE `Account` = '" + Charr.MyClient.Account + "'", DataBase.Connection);

    Command.ExecuteNonQuery();

    }

    catch (Exception Exc)

    {

    General.WriteLine(Convert.ToString(Exc));

    Connection.Close();

    Connect("root", "jenny");

    if (World.SaveAllChars())

    General.WriteLine("Connection to mysql server reinitiated");

    else

    General.WriteLine("Connection Error, server restarting! " + DateTime.Now);

    }

    }

     

     

    The error i get is Connection must be valid and open.... like connection with MySql broke and server can't save informations. I Use AppServ wich include Apache server and MySql.

     

    So Anyone can help me fixing my problem?

    Friday, November 21, 2008 10:08 PM

All replies

  • You should open database connection before you call ExecuteNonQuery. I do not see any code that does it. If you keep your database connection opened all the time and rely on it, then it is not the best solution, since connections could be closed or dropped without any notification. The best strategy is to open connection only before call to the database and close it right after it completed. It will save resources and provides more reliable environment for your application.

    Friday, November 28, 2008 11:50 AM
    Moderator