所以...我有一些靜態類與一些方法,它返回一些數據到我的數據表。Busy DataReader打破我的網站
問題是多訪問到這個方法。何時不同的客戶端會話在同一時間調用此方法 DataReaded失敗,錯誤我需要關閉當前命令(DataReader),然後再啓動新的。我甚至試圖用鎖但這沒有任何意義。
private RepGroupsDataSourcelocker = Object()
public RepGroupsDataSource() : array[(string * int)]
lock(RepGroupsDataSourcelocker)
def res = linq<#from pr in _Rep_Permission
from rg in _Rep_Group
where (pr.ID_User == System.Web.HttpContext.Current.User.Identity.Name)
where (rg.RepGroup_ID == pr.ID_RepGroup)
order by rg.nOrder
select (rg.RepGroup_Name, rg.RepGroup_ID)
#>
res.Take(7).ToArray()
這只是示例代碼,它在任何linq2sql,SqlAdapter Fill命令上都失敗。
下面是詳細信息:
System.InvalidOperationException was unhandled by user code
Message = There is a designated this command Command open DataReader, which requires the prior close.
Source = System.Data
StackTrace:
in System.Data.SqlClient.SqlInternalConnectionTds.ValidateConnectionForExecute (SqlCommand command)
in System.Data.SqlClient.SqlConnection.ValidateConnectionForExecute (String method, SqlCommand command)
in System.Data.SqlClient.SqlCommand.ValidateCommand (String method, Boolean async)
in System.Data.SqlClient.SqlCommand.RunExecuteReader (CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
in System.Data.SqlClient.SqlCommand.RunExecuteReader (CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader (CommandBehavior behavior, String method)
in System.Data.SqlClient.SqlCommand.ExecuteDbDataReader (CommandBehavior behavior)
in System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader (CommandBehavior behavior)
in System.Data.Common.DbDataAdapter.FillInternal (DataSet dataset, DataTable [] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
in System.Data.Common.DbDataAdapter.Fill (DataTable [] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
in System.Data.Common.DbDataAdapter.Fill (DataTable dataTable)
in Flow_WEB_Nemerle.SQLModule.GetReport (String Param1, Int32 Param2, Int32 Group, Int32 DayOfMonth, String ContactHour, Int32 MyCase, Boolean ForDia, Int32 step, Int32 maximumRows, Int32 startRowIndex) in D: \ SVN \ FlowServer \ trunk \ FS WEB \ Flow_WEB_Nemerle2 \ SQLReportModule.n: line 96
InnerException:
我怎樣才能避免這種麻煩不爲它創建一個Windows服務/ WCF。我想要真正快速的解決方案...也許我需要動態類的方法?
你的類不應該是靜態的,但方法應該是靜態的,如果你發佈類的方法,那麼我們可以幫助你更好。 – 2011-04-12 10:37:35
爲什麼你有靜態類?將它們改爲實例類,你會沒事的。 – 2011-04-12 10:38:23
@Waqas - 不,該方法不應該是靜態的,因爲它會導致非常相同的行爲。 – 2011-04-12 10:40:02