簡體   English   中英

C# 捕獲 mssqltriger 異常

[英]C# catch mssqltriger exception

http://weblogs.asp.net/guys/archive/2005/05/20/408142.aspx

我需要在 msssql DB 中捕獲觸發異常,但我不知道哪個代碼適用於此。 如何在 C# 中捕獲 mssql 觸發器?

我想抓住這個錯誤:

Error Insert or Update: could not insert: [WebCrawler.Core.Entities.Advertisements][SQL: INSERT INTO [Advertisements] (Name, Description, DepartureDate, Url, Price, HollidayDuration, BookingDate, Cities_idCities, Areas_idAreas, Countries_idCountries, Agencies_idAgencies) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); select SCOPE_IDENTITY()]

它被觸發器拋出。

打開“第一次機會異常”(ctrl-alt-e)並選中“公共語言運行時異常”旁邊的“拋出”框。 從 IDE 運行您的代碼,並觀察捕獲的異常。 取它呈現給您的名稱,並將其放入 C# 代碼中的 catch 塊中。

完成后不要忘記關閉“第一次機會例外”的“拋出”選項。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM