简体   繁体   English

SQL PRINT与InfoMessage

[英]SQL PRINT with InfoMessage

How do you go about distinguishing between and error message and a PRINT in a SQL Query? 如何在SQL查询中区分错误消息和PRINT?

void myConnection_InfoMessage(object sender, SqlInfoMessageEventArgs e)
{
     if (e.Errors.Count > 0)
     {
     }
}

It sees PRINT statements as an error. 它将PRINT语句视为错误。

How can I distinguish between the two? 如何区分两者?

For each error, which is an SqlError object, you can examine the Class property: 对于每个错误(它是一个SqlError对象),您可以检查Class属性:

Messages with a severity level of 10 or less are informational and indicate problems caused by mistakes in information that a user has entered. 严重级别为10或更低的消息仅供参考,表示由于用户输入的信息错误而引起的问题。 Severity levels from 11 through 16 are generated by the user, and can be corrected by the user. 严重级别从11到16由用户生成,并且可以由用户进行校正。 Severity levels from 17 through 25 indicate software or hardware errors. 严重级别从17到25表示软件或硬件错误。 When a level 17, 18, or 19 error occurs, you can continue working, although you might not be able to execute a particular statement. 当发生17、18或19级错误时,尽管您可能无法执行特定的语句,但是您可以继续工作。

PRINT s come through with a Class of 0, but generally you should (as it says) treat 10 or lower as "informational" rather than a real error. PRINTClass为0,但通常您应该(如它所说)将10或更低的值视为“信息性”,而不是实际错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM