所以我有這樣的客戶機/服務器的遊戲,會出現以下問題:除非服務器調用SQL數據庫中使用函數調用來更新玩家C#SQL數據庫中不保存數據
一切正常「 UpdatePlayer」。
示例:您使用角色登錄,進入空間並死亡。服務器調用函數DestroyUser設置當玩家死亡時發生的事情,然後調用「UpdatePlayer(Victomcheck)」,其中Victomcheck =死亡玩家。
服務器調用UpdatePlayer後,數據庫變得混亂,並且不會保存任何數據。
示例:您啓動客戶端,註冊用戶,並且當您使用登錄名和密碼註銷並再次登錄時,表示密碼不正確(數據未保存到sql數據庫)。
調試輸出: 拋出異常: 'System.Data.SqlClient.SqlException' 在System.Data.dll中
問題發生在SQLDataBase.cs文件在線121(它評論在下面的代碼):
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);
}
這裏的updateplayer功能:
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);
}
我不明白爲什麼這個問題發生,請大家幫忙。我可以提供您需要的任何其他必需的代碼。非常感謝你!
什麼是System.Data.SqlClient.SqlException的完整異常消息?內部異常消息是什麼(如果有的話)?這就是什麼會告訴你什麼是錯的。 – user1666620
它只會說「拋出的異常:System.Data.dll中的'System.Data.SqlClient.SqlException'」。如何查看完整的異常消息和內部消息?對不起,我對C#很新... –
要獲取異常消息請看ex.Message。內部異常可以在ex.InnerException中找到,並帶有ex.InnerException.Message消息(小心,InnerException可以爲null!) –