日期:2014-05-18  浏览次数:21130 次

特特急????异常详细信息: System.InvalidOperationException: ExecuteReader 要求已打开且可用的连接。连接的当前状态为已关闭。????
异常详细信息: System.InvalidOperationException: ExecuteReader 要求已打开且可用的连接。连接的当前状态为已关闭。

源错误: 


行 232: myCommand.CommandType = CommandType.Text;
行 233: SqlDataReader dr = null;
行 234: dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);//???????????????????????
行 235:
行 236: return dr;
 

源文件: c:\Inetpub\wwwroot\TragramMini\WebTragMini\App_Code\Folder.cs 行: 234 

堆栈跟踪: 


[InvalidOperationException: ExecuteReader 要求已打开且可用的连接。连接的当前状态为已关闭。]
  System.Data.SqlClient.SqlConnection.GetOpenConnection(String method) +861892
  System.Data.SqlClient.SqlConnection.ValidateConnectionForExecute(String method, SqlCommand command) +9
  System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async) +101
  System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +73
  System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
  System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +122
  System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior) +62
  TangramMiniWeb.Folder.GetFolders() in c:\Inetpub\wwwroot\TragramMini\WebTragMini\App_Code\Folder.cs:234
  TangramMiniWeb.MailDesktop.BindFolderData() in c:\Inetpub\wwwroot\TragramMini\WebTragMini\Email\MailDesktop.aspx.cs:29
  TangramMiniWeb.MailDesktop.Page_Load(Object sender, EventArgs e) in c:\Inetpub\wwwroot\TragramMini\WebTragMini\Email\MailDesktop.aspx.cs:23
  System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
  System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
  System.Web.UI.Control.OnLoad(EventArgs e) +99
  System.Web.UI.Control.LoadRecursive() +47
  System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint

源码为:

  public SqlDataReader GetFolders()
  {

  ///创建链接
  SqlConnection myConnection = new SqlConnection(conString);
  if(myConnection.State==ConnectionState.Open)
  myConnection.Open();
  ///定义SQL语句
  string cmdText = "SELECT * FROM Folders";
  SqlCommand myCommand = new SqlCommand(cmdText, myConnection);

  myCommand.CommandType = CommandType.Text;
  SqlDataReader dr = null;
  dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);//???????????????????????

  return dr;
  }

  private string conString = ConfigurationManager.AppSettings["EngString"];


特急谢谢
雅琦
 


------解决方案--------------------
if(myConnection.State==ConnectionState.Close) 试试 

------解决方案--------------------
if(myConnection.State==ConnectionState.Open) 

-->
if(myConnection.State==ConnectionState.Closed)
------解决方案--------------------
我倒..
改成这样子:
public SqlDataReader GetFolders() 


///创