【问题标题】: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。