2008-10-29 20 views
6

, bir hata aşağıdaki gibi olsun:Hangi saklı yordamda hangi hatanın oluştuğunu nasıl anlarım? Benim MS SQL 2005 veritabanı üzerinde belirli bir saklı yordam çalıştırmayı denediğinizde

Subquery returned more than 1 value. This is not permitted when 
the subquery follows =, !=, <, <= , >, >= or when the subquery 
is used as an expression 

sorguda SP çok uzun, diğeri SP çağırır. Bu hata açıkça SQL tarafından üretiliyor ve çağrı yığınının sonuna kadar döndü, ancak hangi SP veya satır numarasının soruna neden olduğunu belirtmeden. Hatanın nerede bulunduğunu nasıl bulabilirim, böylece daha kolay hata ayıklayabilirim?

cevap

5

Try/Catch block'u kullanmak, aradığınız şeyi size vermelidir. Bir CATCH bloğu kapsamında

, aşağıdaki sistem fonksiyonları CATCH blok yürütülecek neden hata hakkında bilgi edinmek için kullanılabilir:

* ERROR_NUMBER() returns the number of the error. 
* ERROR_SEVERITY() returns the severity. 
* ERROR_STATE() returns the error state number. 
* ERROR_PROCEDURE() returns the name of the stored procedure or trigger where the error occurred. 
* ERROR_LINE() returns the line number inside the routine that caused the error. 
* ERROR_MESSAGE() returns the complete text of the error message. The text includes the values supplied for any substitutable parameters, such as lengths, object names, or times. 

Yani, senin durumunda, ERROR_LINE() ve ERROR_PROCEDURE() istediğiniz gibi olmalıdır ...

+0

Çalışıyor! Teşekkürler! – apenwarr

İlgili konular