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

推荐订阅源

S
Secure Thoughts
Security Latest
Security Latest
Simon Willison's Weblog
Simon Willison's Weblog
O
OpenAI News
GbyAI
GbyAI
L
LINUX DO - 最新话题
A
Arctic Wolf
T
Tor Project blog
G
GRAHAM CLULEY
I
InfoQ
博客园_首页
IT之家
IT之家
The Register - Security
The Register - Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
Blog — PlanetScale
Blog — PlanetScale
N
Netflix TechBlog - Medium
K
Kaspersky official blog
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
U
Unit 42
PCI Perspectives
PCI Perspectives
量子位
P
Palo Alto Networks Blog
S
Securelist
T
Troy Hunt's Blog
博客园 - 【当耐特】
Recorded Future
Recorded Future
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
Engineering at Meta
Engineering at Meta
T
The Blog of Author Tim Ferriss
博客园 - 聂微东
罗磊的独立博客
N
News and Events Feed by Topic
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
NISL@THU
NISL@THU
C
Cisco Blogs
T
Threatpost
有赞技术团队
有赞技术团队
Forbes - Security
Forbes - Security
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
T
The Exploit Database - CXSecurity.com
Cloudbric
Cloudbric
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
C
Cyber Attacks, Cyber Crime and Cyber Security

博客园 - 克仔

克仔嘅第一次。。。“浮潜” 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