ExecuteReader需要一个开放和可用的连接。连接的当前状态是连接当尝试通过ASP.NET Online连接到MSSQL数据库时,当两个或多个人同时连接时,我将得到以下信息:ExecuteReader需要一个开放和可用的连接。连接的当前状态是连接。该站点在我的本地主机服务器上运行良好。这是粗略的代码。public Promotion retrievePromotion(){
int promotionID = 0;
string promotionTitle = "";
string promotionUrl = "";
Promotion promotion = null;
SqlOpenConnection();
SqlCommand sql = SqlCommandConnection();
sql.CommandText = "SELECT TOP 1 PromotionID, PromotionTitle, PromotionURL FROM Promotion";
SqlDataReader dr = sql.ExecuteReader();
while (dr.Read())
{
promotionID = DB2int(dr["PromotionID"]);
promotionTitle = DB2string(dr["PromotionTitle"]);
promotionUrl = DB2string(dr["PromotionURL"]);
promotion = new Promotion(promotionID, promotionTitle, promotionUrl);
}
dr.Dispose();
sql.Dispose();
CloseConnection();
return promotion;}我能知道哪里可能出了问题吗?我该如何解决呢?编辑:不要忘记,我的连接字符串和连接都是静态的。我相信这就是原因。请指点。public static string conString = ConfigurationManager.ConnectionStrings["dbConnection"].ConnectionString;
public static SqlConnection conn = null;
1 回答
- 1 回答
- 0 关注
- 448 浏览
添加回答
举报
0/150
提交
取消