How do you go about distinguishing between and error message and a PRINT in a SQL Query?
void myConnection_InfoMessage(object sender, SqlInfoMessageEventArgs e)
{
if (e.Errors.Count > 0)
{
}
}
It sees PRINT statements as an error.
How can I distinguish between the two?
For each error, which is an SqlError
object, you can examine the Class
property:
Messages with a severity level of 10 or less are informational and indicate problems caused by mistakes in information that a user has entered. Severity levels from 11 through 16 are generated by the user, and can be corrected by the user. Severity levels from 17 through 25 indicate software or hardware errors. When a level 17, 18, or 19 error occurs, you can continue working, although you might not be able to execute a particular statement.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.