我正在运行一个游戏模拟器,它一直在与连接崩溃

时间:2015-03-22 17:42:07

标签: c#

好的,所以我运行游戏模拟器并没有关闭连接所以我在这里搜索并发现了一些代码用

替换它
    private static SqlDatabaseClient CreateClient(int Id)
    {
        Int32 returnId = 0;

        try
        {
            using (MySqlConnection connection = new MySqlConnection(GenerateConnectionString()))
            {
                connection.Open();

                if (connection.State == ConnectionState.Open)
                {
                    returnId = Id;
                }

                return new SqlDatabaseClient(Id, Connection);
            }

        }
        catch (Exception ex)
        {
            Trace.Write(ex.Message);
        }
        finally
        {
            if (Connection.State == ConnectionState.Open)
            {
                Connection.Close();

                    if (Connection.State == ConnectionState.Closed)
                    {
                        returnId = Id;
                    }

            }
        }
    }

但当我把它放入时我会收到错误

  

“错误1'AGame.Storage.SqlDatabaseManager.CreateClient(int)':不是全部   代码路径返回一个   值C:\ inetpub \ wwwroot \ Emulator \ Storage \ SqlDatabaseManager.cs 204 35 AGame“   那行是“private static SqlDatabaseClient CreateClient(int   ID)“

1 个答案:

答案 0 :(得分:0)

根据上面的评论,您应该将catch块更改为:

catch (Exception ex)
{
  Trace.Write(ex.Message);
  throw;
}

另外,你确定你的finally块有效吗?什么是'连接'对象?