惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
SegmentFault 最新的问题
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Attack and Defense Labs
Attack and Defense Labs
F
Full Disclosure
Vercel News
Vercel News
N
News | PayPal Newsroom
The GitHub Blog
The GitHub Blog
H
Hacker News: Front Page
H
Heimdal Security Blog
P
Privacy International News Feed
博客园 - 司徒正美
Google DeepMind News
Google DeepMind News
N
Netflix TechBlog - Medium
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cisco Blogs
L
Lohrmann on Cybersecurity
D
Docker
Recent Announcements
Recent Announcements
Security Archives - TechRepublic
Security Archives - TechRepublic
人人都是产品经理
人人都是产品经理
C
CXSECURITY Database RSS Feed - CXSecurity.com
P
Proofpoint News Feed
T
Tailwind CSS Blog
C
Check Point Blog
博客园 - 叶小钗
Google Online Security Blog
Google Online Security Blog
Martin Fowler
Martin Fowler
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
S
Secure Thoughts
博客园 - Franky
博客园_首页
阮一峰的网络日志
阮一峰的网络日志
P
Palo Alto Networks Blog
Latest news
Latest news
量子位
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 三生石上(FineUI控件)
The Cloudflare Blog
Last Week in AI
Last Week in AI
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Cyberwarzone
Cyberwarzone
小众软件
小众软件
Cisco Talos Blog
Cisco Talos Blog
Hacker News: Ask HN
Hacker News: Ask HN
T
Threatpost
T
Tenable Blog
P
Privacy & Cybersecurity Law Blog
WordPress大学
WordPress大学

博客园 - 克仔

克仔嘅第一次。。。“浮潜” Exact ADC之Paintball大戦 - 克仔 - 博客园 .NET Compact Framework里的DateTimePicker Control显示錯误的month selection list .NET CF v1的Form.ShowDialog(Me)里的Me在不能用了! .NET CF里的toolbar image在Windows Mobile 2003 SE消失了。 先嚟為《達文西的密碼》電影熱熱身。 汽油起價 - 加油站車龍。 我嘅第一部O2 Xda ll mini 《達文西的密碼》登上大银幕 Single Instance Appplication in .NET CF 丹•布朗 《數字城堡》 全新ARM base PocketPC 2003 Emulator Beta 已登場。 向左走,向右走? 全新旅途。。。 如何在ASP.NET里用HtmlInputFile控件来上载文件。 達文西的密碼 - 後記。 達文西的密碼。 如何用ASP.NET里的State Management Database来储存Session Variable。 如何用DataSet.GetChanges来提升数据库资料更新效率。 Deamon Tool
如何用SqlConnection类的InfoMessage事件来显示Stored Procedure的PRINT讯息。
克仔 · 2005-04-07 · via 博客园 - 克仔

(華版)

我想很多程序员都会面对一个问题。。。就是如何调试(Debug)Stored Procedure;以下是我在研究ADO.NET时所得到的心得,在此跟大家分享以下。

只需在VB.NET或C#代码里,添加SqlConnect_InfoMessage事件,然后就从SqlInfoMessageEventArgs读取所有的PRINT/ERROR讯息就可以了 。

所返回的讯息种类:
  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(ByVal sender As ObjectByVal e As System.Data.SqlClient.SqlInfoMessageEventArgs) Handles cn.InfoMessage

        
'声明变量
        Dim se As SqlError

        
With ListBox1
            
'显示讯息
            .Items.Add("+ Message: " & e.Message)
            .Items.Add(
" + Source: " & e.Source)

            
'检查SqlErrorCollection是否空的
            If e.Errors.Count > 0 Then
                
'读取每一个SqlError对象讯息
                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

            
'选最后一个记录
            .SelectedIndex = .Items.Count - 1
        
End With

    
End Sub

以下是Stored Procedure的代码,

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