我有一個Web服務,它有一些數據訪問方法。這種特殊的方法只能讀取數據。它不會執行任何插入,更新,也不會執行任何觸發器以導致插入或更新。我們有一個錯誤報告記錄爲違反主鍵約束。正如我之前所說的,這種方法不會插入任何東西。這裏是調用堆棧:違反主鍵約束讀取
The METHOD_NAME() method failed with an unhandled exception.
[EXCEPTIONS] #1:SqlException(Violation of PRIMARY KEY constraint 'CONSTRAINT_NAME'. Cannot insert duplicate key in object 'dbo.TABLE_NAME'.
The statement has been terminated.) [SITE] Logged in Anon.DLL [DETAILS] Level=Error
[STACK] 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(TdsParserStateObject stateObj)
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 Anon.DataAccess.Common.DataAccessBase`4.ExecuteReader() in Anon\DataAccessBase.cs:line 183
at Anon.DataAccess.GetSomething() in Anon\SomethingDal.cs:line 31
at Anon.Service.Manager.GetSomething() in Anon\Manager.cs:line 53
at Anon.WebService.GetSomething() in Anon\WebService.asmx.cs:line 47
有此服務的其他方法可能會產生錯誤,但他們將不得不需單獨調用。當我只進行讀取時,如何獲得插入錯誤?這兩種方法是否可能同時運行,並將錯誤報告給錯誤的連接?
這工作正常99.9999%的時間,但這一次有些東西被交叉了。
沒有臨時表嗎? – 2011-03-07 19:59:04
你在調用存儲過程嗎?您是否使用過SQL Profiler查看究竟調用了什麼? – Oded 2011-03-07 20:00:16
我正在調用存儲過程。我無法重現此錯誤,但它肯定是記錄的。沒有臨時表。 – 2011-03-07 20:44:07