Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > SQL Server กับ Stored Procedure สอนเขียน Stored Procedure บน SQL Server Database > ตอนที่ 13 : การ Debug Stored Procedure บน Visual Studio 2010,2012,2013,2015 และอื่น ๆ



Clound SSD Virtual Server

ตอนที่ 13 : การ Debug Stored Procedure บน Visual Studio 2010,2012,2013,2015 และอื่น ๆ

ตอนที่ 13 : การ Debug Stored Procedure บน Visual Studio 2010,2012,2013,2015 และอื่น ๆ สำหรับฟีเจอร์นี้ถือว่าเป็นจุดเล่นและความสามารถน่าสนใจมาก เพราะเหตุลผก็คือใน SQL Server รุ่นใหม่ ๆ มันสามารถใช้ Visual Studio ทำการ Debug ตัว Stored Procedure ร่วมกับการเขียนโปรแกรมอื่น ๆ บน Visual Studio ได้เลย ซึ่งปัญหาในการเขียน Stored ยุคแรก ๆ ก็คือแทบจะไม่มีวิธีการ Debug ตัว Stored Procedure ได้เลย การหาข้อผิดพลาดระหว่าง Runtime นั้นเป็นไปได้ยากมา นอกจากการใช้วิธี PRINT เพื่อดูค่าทาง Result ด้วยเหตุนี้เอง Stored Procedure จึงไม่ค่อยได้รับความนิยมมากนัก และถือว่าเป็นจุดเด่นมาก ๆ ที่ใน Visual Studio รุ่นใหม่ ๆ มีฟีเจอร์นี้ขึ้นมาด้วย โดยเราสามารถที่จะ Debug ได้เฉพาะ Stored Procedure ก็ได้ หรือจะ Debug โปรแกรมตั้งแต่ Application จนมาถึงการเรียกใช้งาน Stored Procedure

Stored สำหรับทดสอบในการ Debug โปรแกรม
CREATE PROCEDURE [dbo].[myStoredProcedure]
	@pRow	INT	
AS
BEGIN
	
	-- Declare Table
	DECLARE @temp TABLE
	(
		RowID INT,
		Name VARCHAR(50),
		LastName VARCHAR(50)
	)

	-- Variable
	DECLARE @i INT
	SET @i = 1

	-- Loop Insert Table
	WHILE (@i <= @pRow)
		BEGIN
			INSERT INTO @temp (RowID,Name,LastName) VALUES ((@i),'Weerachai','Nukitram')
			SET @i = @i + 1 
		END -- WHILE

	-- Variable
	DECLARE @j INT
	DECLARE @iRow INT
	DECLARE @sName VARCHAR(50)
	DECLARE @sLastName VARCHAR(50)

	-- Set Variable
	SET @j = 1
	SELECT @iRow = COUNT(*) FROM @temp

	-- Loop Display Row
	WHILE (@j <= @iRow)
		BEGIN 
			-- Select from table
			SELECT @sName = Name , @sLastName = LastName
			FROM @temp WHERE RowID = @i

			-- Print output
			PRINT ' Row : ' + CONVERT(VARCHAR,@j) + ', Name : ' + @sName + ', LastName : ' + @sLastName
         
		SET @j = @j + 1 
		END -- WHILE

END


Note!! Visual Studio 2010 สามารถ Debug ได้แค่ SQL Server 2008 ลงไป ส่วน รุ่นอื่น ๆ จะต้องใช้ให้สูงกว่า Version ที่โปรแกรม Limit ไว้

Example 1 การ Debug Stored Procedure บน Visual Studio 2010

Debug Stored Procedure

เลือกที่ Server Explorer คลิกขวา Add Connection

Debug Stored Procedure

ข้อมูลที่จะติดต่อกับ SQL Server








Debug Stored Procedure

รายการ SQL Server แสดงใน Server Explorer ของ Visual Studio

Debug Stored Procedure

เลือกชื่อ Stored Procedure ที่ต้องการ

Debug Stored Procedure

คลิกขวาเลือกที่ Open

Debug Stored Procedure

หลังจากที่แสดง Stored Procedure เราสามารถกำหนด Breakpoints ที่จะ Debugได้

Debug Stored Procedure

คลิกขวที่ Stored Procedure -> Step Info Stored Procedure

Debug Stored Procedure

ในกรณีที่ Stored มี Parameters จะแสดง Dialog ให้ทำการ Input ค่าต่าง ๆ

Debug Stored Procedure

จากนั้นตัว Cursor จะวิ่งมายัง Breakpoints และหยุดให้เราตรวจสอบค่าต่าง ๆ ซึ่งสามารถ Debug Step ได้เหมือนกับ Visual Studio เช่น F10 , F11 , F5 เป็นต้น

Debug Stored Procedure

การ Control Step ต่าง ๆ

Example 2 การ Debug Stored Procedure บน Visual Studio 2012,2013 และอื่น ๆ

Debug Stored Procedure

ในการ Debug ตัว Stored Procedure ตั้งแต่ Visual Studio 2012 ขึ้นไป

Debug Stored Procedure

ให้คลิกที่เมนู VIEW -> SQL Server Object Explorer

Debug Stored Procedure

ในกรณีที่แสดงข้อความ
Untable to connect a database and browse object.

Incompatible version of sql server data tools and database runtime components are installed on this computer. Wen I click on Lear more... and Get the latest version of SQL Server Data Tools..., these two page are not available.

แสดงทำการดาวน์โหลดและติดตั้งตัว SQL Server Data Tools. ให้เรียบร้อยเสียก่อน

Microsoft SQL Server Data Tools
ล่าสุด
https://msdn.microsoft.com/en-us/library/mt204009.aspx

สำรอง
http://www.microsoft.com/en-us/download/details.aspx?id=36843
http://www.microsoft.com/en-us/download/details.aspx?id=42313


Debug Stored Procedure

เลือก Version ให้ตรงกับ Visual Studio ที่กำลังใช้งาน

Debug Stored Procedure

ติดตั้ง Microsoft SQL Server Data Tools

Debug Stored Procedure

แสดงรายการของ SQL Server

Debug Stored Procedure

คลิกขวาที่ SQL Server -> Add SQL Server

Debug Stored Procedure

ทำการ Authen ตัว SQL Server ที่จะเชื่อมต่อ








Debug Stored Procedure

แสดงรายการของ SQL Server ที่ทำการ Add เข้ามา

Debug Stored Procedure

เลือกที่ Stored Procedure ที่จะทำการ Debug

Debug Stored Procedure

คลิกวาเลือก Debug Procedure

Debug Stored Procedure

ใส่ค่า Parameters ในกรณีที่ต้องการให้มีค่าส่งไปด้วย

Debug Stored Procedure

โปรแกรมจะสร้าง New Query ให้ใหม่ โดย Input ค่าต่าง ๆ ไปให้ด้วย

Debug Stored Procedure

เราสามารถ Debug เข้าไปใน Step ย่อยของ Procedure ด้วยการกด F11

Debug Stored Procedure

ถ้ามี Breakpoint จะหยุดและแสดงค่าต่าง ๆ ของตัวแปร

   
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2015-09-12 08:50:55 / 2017-03-24 22:36:39
  Download : No files
 Sponsored Links / Related

 
ตอนที่ 1 : รู้จักและการเขียน Stored Procedure บน SQL Server (SQL Server : Stored Procedure)
Rating :

 
ตอนที่ 2 : การสร้าง Parameters รับค่าบน Stored Procedure (SQL Server : Stored Procedure)
Rating :

 
ตอนที่ 3: การ Print และแสดงผลบน Stored Procedure (SQL Server : Stored Procedure)
Rating :

 
ตอนที่ 4 : การสร้างตัวแปร Declare Variable บน Stored Procedure (SQL Server : Stored Procedure)
Rating :

 
ตอนที่ 5 : การสร้าง Declare Table สร้างตัวแปรแบบตาราง (SQL Server : Stored Procedure)
Rating :

 
ตอนที่ 6 : การสร้าง Loop ข้อมูลบน Stored Procedure (SQL Server : Stored Procedure)
Rating :

 
ตอนที่ 7 : การใช้ Cursor บน Stored Procedure (SQL Server : Stored Procedure)
Rating :

 
ตอนที่ 8 : การใช้ If ....Else If...Else สร้างเงื่อนไข (SQL Server : Stored Procedure)
Rating :

 
ตอนที่ 9 : การใช้ Try Catch บน Stored Procedure (SQL Server : Stored Procedure)
Rating :

 
ตอนที่ 10 : การใช้ OUTPUT และ OUT เพื่อส่งค่ากลับ (SQL Server : Stored Procedure)
Rating :

 
ตอนที่ 11 : การใช้ Transaction เพื่อ Rollback และ Commit (SQL Server : Stored Procedure)
Rating :

 
ตอนที่ 12 : การใช้ Cursor ระหว่าง (Between) Stored Procedure (SQL Server : Stored Procedure)
Rating :

 
ตอนที่ 14 : การสร้าง View Table บน SQL Server Database (SQL Server : View Table)
Rating :

 
ตอนที่ 15 : การสร้าง Trigger บน SQL Server Database (SQL Server : Trigger)
Rating :

 
ตอนที่ 16 : การสร้าง Function บน Server Database (SQL Server : Function)
Rating :

 
ตอนที่ 17 : PHP เรียกใช้ EXEC/CALL - SQL Server Stored Procedure ด้วย sqlsrv และ pdo
Rating :

 
ตอนที่ 18 : Visual Basic (VB.Net) เรียกใช้ EXEC SQL Server Stored Procedure
Rating :

 
ตอนที่ 19 : Java เรียกใช้ EXEC/CALL - SQL Server Stored Procedure ด้วย (JDBC)
Rating :

 
ตอนที่ 20 : Visual C# (C# .Net) เรียกใช้ EXEC/CALL - SQL Server Stored Procedure
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่