【问题标题】:While running in Localhost it's working but after deployed in Azure getting Error在 Localhost 中运行时它正在工作,但在 Azure 中部署后出现错误
【发布时间】:2018-04-29 08:47:02
【问题描述】:

在 Localhost 中运行时它正在工作,但在 Azure 中部署后出现错误请查看下面的屏幕截图

错误是:已经有一个打开的 DataReader 与此命令关联,必须先关闭

【问题讨论】:

标签: c# azure entity-framework-6 asp.net-web-api2


【解决方案1】:

已经有一个打开的 DataReader 与此命令关联,必须先关闭

根据异常,看来你没有正确关闭DataReader。

尽量避免使用这样的阅读器:

using(SqlConnection connection = new SqlConnection("connection string"))
{

    connection.Open();

    using(SqlCommand cmd = new SqlCommand("SELECT * FROM SomeTable", connection))
    {
        using (SqlDataReader reader = cmd.ExecuteReader())
        {
            if (reader != null)
            {
                while (reader.Read())
                {
                    //do something
                }
            }
        } // reader closed and disposed up here

    } // command disposed here

} //connection closed and disposed here

有关解决此问题的更多信息,您可以参考此link

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-25
    • 1970-01-01
    • 1970-01-01
    • 2019-09-28
    • 1970-01-01
    • 1970-01-01
    • 2021-06-18
    • 2020-03-07
    相关资源
    最近更新 更多