How to Use the infomessage event of the sqlconnection class to display the Print message of stored procedure.

Source: Internet
Author: User
Tags sql error

(Domestic version)



I think a lotProgramMembers will face a problem... This is how to debug stored procedure. The following are my experiences in studying ADO. net.

Only in VB. NET or C #CodeAdd the sqlconnect_infomessage event, and then read allPrint/ErrorThe message is enough.

Types of returned messages:

Source= The class that return the information.

Error = T-SQL/database error number.

Server = SQL error serverity (please refer to msdn for detail information ).

Line = The line number of the T-SQL that cause the output.

Message= Output/error message.

Private   Sub cn_infomessage () Sub Cn_infomessage ( Byval Sender As   Object , Byval E As System. Data. sqlclient. sqlinfomessageeventargs) Handles CN. infomessage


' Declare Variables

Dim Se As Sqlerror


With Listbox1

' Display message

. Items. Add ( " + Message: "   & E. Message)

. Items. Add ( " + Source: "   & E. Source)


' Check whether sqlerrorcollection is empty

If E. errors. Count >   0   Then

' Read each sqlerror object message

For   Each Se In E. Errors

. Items. Add ( " ? Error: "   & Se. Number)

. Items. Add ( " ? Level: "   & Se. Server)

. Items. Add ( " ? Line: "   & Se. linenumber)

. Items. Add ( " ? Message: "   & Se. Message)

. Items. Add ( " ************************** " )

Next

End   If


' Select the last record

. Selectedindex = . Items. Count -   1

End   With


End sub

The following is the stored procedure code,

Create   Procedure Custordersordersex

(

@ Customerid Nchar ( 5 ),

@ Count Int Output

)

As


-- Debug message

Print   ' Debug start '

Print   ' @ Customerid = '   + @ Customerid


Select Orderid,

Orderdate,

Requireddate,

Shippeddate

From Orders

Where Customerid = @ Customerid

Order   By Orderid


-- Debug message

Print @ Rowcount

Print   ' Debug end '


Set @ Count = @ Rowcount

Set Quoted_identifier Off  


Go


Click "Next" to "Next Generation.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.