调用UpdatePlayer函数后,C#sql数据库不保存数据

时间:2016-03-07 14:46:26

标签: c# sql database

所以我有这个客户端/服务器游戏,并出现以下问题:

除非服务器调用sql数据库以使用名为“UpdatePlayer”的函数更新播放器,否则一切正常。

示例:您使用角色登录,进入太空并且您死亡。服务器调用函数DestroyUser,其中设置当玩家死亡时发生的事情然后它调用“UpdatePlayer(Victomcheck)”,其中Victomcheck =死亡玩家。

服务器调用UpdatePlayer后,数据库变得混乱,之后不会保存任何数据。

示例:启动客户端,注册用户,当您使用登录名和密码注销并再次登录时,它会显示错误的密码(数据未保存到sql数据库中)。

调试输出: 抛出异常:System.Data.dll中的“System.Data.SqlClient.SqlException”

第121行的SQLDataBase.cs文件中出现问题(它在下面的代码中发表了评论):

        DataSet Results = null;
        int RETURN_VALUE = 0;
        try
        {

            Results = new DataSet();
            SqlDataAdapter adapter = new SqlDataAdapter();
            adapter.SelectCommand = Command;
            adapter.Fill(Results); //LINE 121
            Connection.Close();
            Connection = null;

            RETURN_VALUE = System.Convert.ToInt32(Command.Parameters["@RETURN_VALUE"].Value);

        }
        catch (SqlException ex)
        {
            Console.Error.WriteLine(ex.StackTrace);
        }

        return new StoredProcRet(RETURN_VALUE, Results);
    }

这是更新播放器功能:

    static public void UpdatePlayer(int check)
    {

        Player p = new Player(DatabasePlayerAdapter.get_User(check), DatabasePlayerAdapter.get_UserName(check), DatabasePlayerAdapter.get_UserPass(check), DatabasePlayerAdapter.get_UserEmail(check), DatabasePlayerAdapter.get_UserLastIP(check), DatabasePlayerAdapter.get_UserHomePlanet(check), DatabasePlayerAdapter.get_UserLastPlanet(check), DatabasePlayerAdapter.get_UserMoney(check), DatabasePlayerAdapter.get_UserExperience(check), DatabasePlayerAdapter.get_UserLastShip(check), DatabasePlayerAdapter.get_UserPlan2(check), DatabasePlayerAdapter.get_UserPlan3(check), DatabasePlayerAdapter.get_UserPlan4(check), DatabasePlayerAdapter.get_UserPlan5(check), DatabasePlayerAdapter.get_UserPlan6(check), DatabasePlayerAdapter.get_UserPlan7(check), DatabasePlayerAdapter.get_UserPlan8(check), DatabasePlayerAdapter.get_UserPlan9(check), DatabasePlayerAdapter.get_UserShip1(check), DatabasePlayerAdapter.get_UserShip2(check), DatabasePlayerAdapter.get_UserShip3(check), DatabasePlayerAdapter.get_UserShip4(check), DatabasePlayerAdapter.get_UserShip5(check), DatabasePlayerAdapter.get_UserShipMisc1(check), DatabasePlayerAdapter.get_UserShipMisc2(check), DatabasePlayerAdapter.get_UserShipMisc3(check), DatabasePlayerAdapter.get_UserShipMisc4(check), DatabasePlayerAdapter.get_UserShipMisc5(check), DatabasePlayerAdapter.get_UserGuild(check), DatabasePlayerAdapter.get_UserGuildRank(check), DatabasePlayerAdapter.get_UserGuildLent(check), DatabasePlayerAdapter.get_UserGenKills(check), DatabasePlayerAdapter.get_UserVelicKills(check), DatabasePlayerAdapter.get_UserGenVelicExp(check), DatabasePlayerAdapter.get_UserUniversalCredits(check), DatabasePlayerAdapter.get_UserDeaths(check));
        sqlPlay.UpdatePlayer(p);
    }

我不明白为什么会出现这个问题,请帮忙。我可以提供您想要的任何其他所需代码。非常感谢你!

1 个答案:

答案 0 :(得分:0)

经过几个小时的研究,我找到了发生错误的确切行。它发生在游戏中攻击机器人(参与)然后取消攻击(脱离)时。确切的行是:

DatabasePlayerAdapter.set_UserEngageCheck(check, BotMemory.BotNameToCheck(Victom));

所以我认为它可以处理.set_UserEngageCheck,它位于DatabasePlayerAdapter.cs

        public static void set_UserEngageCheck(int i, int value)
    {
        get_Player(i).EngageCheck = value;
    }

有什么想法吗?