| Author |
Topic |
|
Marioi
Posting Yak Master
132 Posts |
Posted - 2005-11-30 : 22:22:08
|
| I am trying to debug UDFs, but when I right-click a UDF in QA, the Debugger option is grayed out. I read that I must be logged on as a non-local-system account in order to use the debugger. Does the sa account qualify? I also tried PRINT in UDFs but they are disallowed. What do you use?TIA. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-12-01 : 01:54:49
|
| According to BOL, the debugger is available for stored procedures. It doesn't say only in there, but since it doesn't list in any other options, I'd say it means only. It is grayed out for me too whereas stored procedures are not.I don't wrap it into a UDF until I am done with my testing. Post what you have and we can show you how to do it.Tara Kizeraka tduggan |
 |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2005-12-01 : 02:35:00
|
| well.. Tara can let me know how to debug the sp from sql analyser.. i tired it put the break point.. but then what should i do .. ???? since in VC++ or .net there is the option of debugging how about in sql analyser???Any links or some information will be of great helps.. Thanks..Sucess Comes to those who Believe in Beauty of their Dream.. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-12-01 : 02:39:29
|
| It's the same thing whether it's in VS or QA. You can't debug UDFs apparently.Tara Kizeraka tduggan |
 |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2005-12-01 : 03:00:48
|
| I m not talking about the Debuggin UDFs .. i m talking about stored procedure.. i guess we can debug stored procedure, from QA?? I want to know about that .. ??? how can i do that ..??? From the object browser i right clicked on the stored procedure and did debug..and stored procedure open in the debug envoirment .. but then what 2 do ??? i put the break point.. pressed f1 etc.. but nothing happened :-(??and then all the button or disabled..???Sucess Comes to those who Believe in Beauty of their Dream.. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-12-01 : 03:53:03
|
| From QA, press F8Expand the Database->Stored ProceduresRight click on the Procedure that you want to Debug and select DebugMadhivananFailing to plan is Planning to fail |
 |
|
|
surendrakalekar
Posting Yak Master
120 Posts |
Posted - 2005-12-01 : 03:59:43
|
| Hi,Debug stored procedure in SQL Server is not like VC/VB. When user right click and select Debug from object browser, it will disply you the "Debug procedure" window. In that window you have to enter the value of each parameter according to there type and then press on Execute button to see the result.But for DTS there is just-in-time debugging option ...In the SQL Server Enterprise Manager console tree, right-click the Data Transformation Services node, and then click Properties. Select the Turn on just-in-time debugging check box.Surendra |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-12-01 : 06:27:41
|
| Do you see a yellow arrow when debugging the stored procedure? If not, then it's not working correctly.Tara Kizeraka tduggan |
 |
|
|
surendrakalekar
Posting Yak Master
120 Posts |
Posted - 2005-12-01 : 07:00:27
|
quote: Originally posted by tkizer Do you see a yellow arrow when debugging the stored procedure? If not, then it's not working correctly.Tara Kizeraka tduggan
No it is not showing me yello arrow while debugging. What could be the problem?Surendra |
 |
|
|
Marioi
Posting Yak Master
132 Posts |
Posted - 2005-12-01 : 12:10:51
|
quote: Originally posted by surendrakalekarNo it is not showing me yello arrow while debugging. What could be the problem?
Robert Vieira says in Professional SS2000 Programming that you must be logged on as a real user, not as a system user account in order to debug 'for real'. |
 |
|
|
Marioi
Posting Yak Master
132 Posts |
Posted - 2005-12-01 : 12:13:55
|
quote: Originally posted by tkizer According to BOL, the debugger is available for stored procedures.
Tara, before I post my UDF, how do you output values of variables to the screen, log, or disk? What do you do to see what's going on? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-12-01 : 12:20:44
|
| You use PRINT statements, but outside of the UDF. You can post a very simple one and not your actual one. Surendra,Apply SQL Server 2000 sp4 to both the database server where you want to debug and to the client where the debugging will occur. Both need the sp4 installed. If that doesn't work, let me know.Tara Kizeraka tduggan |
 |
|
|
Marioi
Posting Yak Master
132 Posts |
Posted - 2005-12-01 : 13:32:53
|
quote: Originally posted by tkizer You use PRINT statements, but outside of the UDF. You can post a very simple one and not your actual one.
Here's one. How do I see values in parameters and variables during various stages of the execution, especially inside the loops?IF EXISTS (SELECT * FROM sysobjects WHERE name = N'fnSplit') DROP FUNCTION fnSplitGO------------------ fnSplit ----------------------CREATE FUNCTION dbo.fnSplit (@RowData nvarchar(4000), @SplitOn nvarchar(5))-- AUTHOR: MI 11/30/05-- Adapted from Seventhnight's posting on http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=50648.-- The function preserved starting and trailing spaces.-- IMPORTANT: Current does NOT support spaces as delimiters. -- PURPOSE: -- Split a uniformly delimited string into a table.-- PARAMETERS:-- @RowData: the string to split.-- @SplitOn: the delimiter.-- RETURNS:-- Table with 2 columns: counter and Data.-- EXAMPLE 1:-- SELECT * FROM dbo.fnSplit -- ('Test|string||that needs to|be||split', -- '|')-- GO-- EXAMPLE 2:-- SELECT * FROM dbo.fnSplit -- (' Test\\\ string\\\that needs to \\\\\\ be \\\ split \\\\\\', -- '\\\')-- GORETURNS @RtnValue table (Id int identity(1,1), Data nvarchar(4000)) AS BEGIN -- Ensure that the SplitOn parameter has at least 1 character. If not, -- we would loop infinitely IF Len(@SplitOn) < 1 BEGIN-- RAISERROR ('Please provide a valid character in the %d parameter.',-- 16, 1, '@SplitOn') Return END ELSE BEGIN Declare @Cnt int Declare @sValue nvarchar(4000) Set @Cnt = 1 While (Charindex(@SplitOn,@RowData)>0) Begin (Select @sValue = Substring(@RowData,1,Charindex(@SplitOn,@RowData)-1)) -- removed LTrim(RTrim()) Insert Into @RtnValue (data) Select Data = @sValue Set @RowData = Substring(@RowData,Charindex(@SplitOn,@RowData)+Len(@SplitOn),len(@RowData)) Set @Cnt = @Cnt + 1 End Select @sValue = @RowData -- removed LTrim(RTrim()) Insert Into @RtnValue (data) Select Data = @sValue END ReturnENDGO-- =============================================-- Example to execute function-- =============================================SELECT * FROM dbo.fnSplit (' Test\\\ string\\\that needs to \\\\\\ be \\\ split \\\\\\', ' ')GO |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-12-01 : 13:41:14
|
Here you go:DECLARE @RowData nvarchar(4000), @SplitOn nvarchar(5)SET @RowData = ' Test\\\ string\\\that needs to \\\\\\ be \\\ split \\\\\\'SET @SplitOn = '\'DECLARE @RtnValue table (Id int identity(1,1), Data nvarchar(4000)) -- Ensure that the SplitOn parameter has at least 1 character. If not, -- we would loop infinitely IF Len(@SplitOn) < 1 BEGIN-- RAISERROR ('Please provide a valid character in the %d parameter.',-- 16, 1, '@SplitOn') Return END ELSE BEGIN Declare @Cnt int Declare @sValue nvarchar(4000) Set @Cnt = 1 While (Charindex(@SplitOn,@RowData)>0) Begin (Select @sValue = Substring(@RowData,1,Charindex(@SplitOn,@RowData)-1)) -- removed LTrim(RTrim()) Insert Into @RtnValue (data) Select Data = @sValue Set @RowData = Substring(@RowData,Charindex(@SplitOn,@RowData)+Len(@SplitOn),len(@RowData)) Set @Cnt = @Cnt + 1 End Select @sValue = @RowData -- removed LTrim(RTrim()) Insert Into @RtnValue (data) Select Data = @sValue END-- =============================================-- Example to execute function-- =============================================SELECT * FROM @RtnValueGOSo you get rid of the idea of a UDF and just work with variables. You can now use PRINT statements. Once it is working to your satisfaction, you convert it to a UDF.Tara Kizeraka tduggan |
 |
|
|
Marioi
Posting Yak Master
132 Posts |
Posted - 2005-12-01 : 13:51:30
|
| Tara,Thanks for that idea. I would never think to defunction a function.Why are functions so restrictive in general? Why must they be deterministic, for example? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-12-01 : 13:58:13
|
quote: Originally posted by Marioi Why are functions so restrictive in general? Why must they be deterministic, for example?
Check out the CREATE FUNCTION topic in SQL Server Books Online. You'll find the information under the "Function Determinism and Side Effects" section of that topic. Also, functions do not need to be deterministic. You just can't call nondeterministic functions within your UDF. But you can pass them to it.Tara Kizeraka tduggan |
 |
|
|
Marioi
Posting Yak Master
132 Posts |
Posted - 2005-12-01 : 14:14:57
|
quote: Originally posted by tkizerCheck out the CREATE FUNCTION topic in SQL Server Books Online. You'll find the information under the "Function Determinism and Side Effects" section of that topic. Also, functions do not need to be deterministic. You just can't call nondeterministic functions within your UDF. But you can pass them to it.
I did read about this in BOL and several other books, but still don't understand why "side effects" such as "changes to some global state of the database, such as an update to a database table, or to some external resource, such as a file or the network" matter. What is the advantage to SS of not being able to call GetDate or NewID or an sProc from a UDF? I guess my question is how are UDFs different from sProcs that allow all those things.You are implying that calling non-deterministic functions can be done some way. How?Do you know why a two-part name is required (dbo.fnFunctionName) for UDFs and not for sProcs? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-12-01 : 14:24:02
|
| I was implying that you can write non-deterministic functions, not that you can call them from within a function.I do not know why a two-part name is required for UDFs. I also can't explain the side effects. We'd need MS engineers to answer those.Tara Kizeraka tduggan |
 |
|
|
Marioi
Posting Yak Master
132 Posts |
Posted - 2005-12-01 : 14:52:57
|
quote: Originally posted by tkizer I was implying that you can write non-deterministic functions, not that you can call them from within a function.
Thanks, Tara. |
 |
|
|
|