2010-09-05 123 views
2

我正在使用C#,.NET和SQL Server與Linq2SQL。.Net LINQ to SQL異常

這個錯誤是什麼意思?

是插入還是讀取/選擇相關的錯誤?

函數Classes.BLL.Save(LPage l)首先從數據庫中選擇COUNT,然後將新記錄插入數據庫。

2010-09-03 04:57:56,264 System.Data.SqlClient.SqlException (0x80131904): Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. 
    at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) 
    at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) 
    at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() 
    at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) 
    at System.Data.SqlClient.SqlDataReader.ConsumeMetaData() 
    at System.Data.SqlClient.SqlDataReader.get_MetaData() 
    at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) 
    at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) 
    at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) 
    at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) 
    at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) 
    at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) 
    at System.Data.Common.DbCommand.ExecuteReader() 
    at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult) 
    at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries) 
    at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query) 
    at System.Data.Linq.ChangeDirector.StandardChangeDirector.DynamicInsert(TrackedObject item) 
    at System.Data.Linq.ChangeDirector.StandardChangeDirector.Insert(TrackedObject item) 
    at System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode) 
    at System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode) 
    at Classes.BLL.Save(LPage l) 

更新:

我知道這是一個超時異常及其從SQL Server的到來。 但錯誤說兩件事情,

1)錯誤Common.DbCommand.ExecuteReader() 和

2)錯誤DataContext.SubmitChanges(ConflictMode failureMode),

所以我想找出錯誤的來源是選擇命令還是插入命令。

+0

你在做什麼?你能告訴我們導致這個錯誤的C#代碼嗎?沒有它,有點難以說....通常,你會使用.ExecuteReader()僅用於選擇數據 - 絕對* NOT *用於插入數據....所以我們需要看看你在做什麼.. .. – 2010-09-05 13:29:21

回答

0

這是一個選擇錯誤 - 插入查詢將通過ExecuteNonQuery完成,如果我沒有記錯的話。雖然,這個錯誤可能會以另一種方式或插入的形式出現。它不是由Linq引起的,而是由Sql Server引起的。

+0

那麼錯誤中的「DataContext.SubmitChanges(ConflictMode failureMode)」是什麼意思? – RuSh 2010-09-05 12:20:17

+0

這意味着錯誤起源於Linq2Sql上下文中的保存。實際的錯誤是連接到sql server超時。 – Femaref 2010-09-05 12:31:55

+0

所以它不是一個選擇錯誤,它的插入錯誤?那麼爲什麼這寫的System.Data.Common.DbCommand.ExecuteReader() – RuSh 2010-09-05 12:36:52

2

此錯誤來自SQL Server,而不是Linq。這僅僅意味着SQL Server的操作在您指定的超時期限(大概30秒)內沒有響應。這可能是由於等待更多或更多記錄上釋放的鎖或其他資源爭用。

0

「Timeout expired。超時時間已過,但操作完成或服務器沒有響應。」

所以這可能是暫停。 你可以ping sql server主機嗎? 您是否嘗試創建UDL文件並測試您的連接? (右鍵點擊文件夾中,創建一個新的空文本文件,重命名爲test.udl,雙擊打開,並在必要的連接數據填寫,然後單擊測試)

親切的問候,

卡雷爾

+0

sql server在本地服務器上,並且連接正在工作。 – RuSh 2010-09-05 12:19:15