Results 1 to 20 of 20

Thread: [RESOLVED] SPROC and VB6 Question

  1. #1

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Resolved [RESOLVED] SPROC and VB6 Question

    I have the following SPROC:

    VB Code:
    1. USE IADATA
    2. IF EXISTS (select * from syscomments where id = object_id ('TestSP'))
    3.     DROP PROCEDURE TestSP
    4.  
    5. GO
    6. CREATE PROCEDURE TestSP
    7.     /*Declare Variables*/
    8.     @ListStr varchar(100) /*Hold Delimited String*/
    9. AS
    10.  
    11. DECLARE @ListTbl Table (InvUnit varchar(50)) /*Creates Temp Table*/
    12. DECLARE @CP int /*Len of String */
    13. DECLARE @SV varchar(50) /*Holds Result */
    14.  
    15. While @ListStr<>''
    16. Begin
    17.     Set @CP=CharIndex(',',@ListStr) /*Sets length of words - Instr */
    18.     If @CP<>0
    19.     Begin
    20.         Set @SV=Cast(Left(@ListStr,@CP-1) as varchar) /*Copies Portion of String*/
    21.         Set @ListStr=Right(@ListStr,Len(@ListStr)-@CP) /*Sets up next portion of string*/
    22.     End
    23.     Else
    24.     Begin
    25.         Set @SV=Cast(@ListStr as varchar)
    26.         Set @ListStr=''
    27.     End
    28.     Insert into @ListTbl Values (@SV) /*Inserts variable into Temp Table*/
    29. End
    30.  
    31. Select InvUnit From @ListTbl LT
    32. INNER Join dbo.Incidents ST on ST.Inv_Unit=LT.InvUnit

    and I am using the following VB code to access the SPROC:

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim adoConn As ADODB.Connection
    3. Dim adoCmd As ADODB.Command
    4. Dim adoRS As ADODB.Recordset
    5. Dim strLegend As String
    6. Dim strData As String
    7.  
    8. Set adoConn = New ADODB.Connection
    9. adoConn.Open connString
    10.  
    11. Set adoRS = New ADODB.Recordset
    12. Set adoCmd = New ADODB.Command
    13.  
    14. With adoCmd
    15.     Set .ActiveConnection = adoConn
    16.     .CommandText = "TestSP"
    17.     .CommandType = adCmdStoredProc
    18.     .Parameters.Append .CreateParameter("ListStr", adVarChar, adParamInput, 100)
    19.     .Parameters("ListStr").Value = "Unit 41,Unit 32,Unit 34,Unit 54"
    20.    
    21.     Set adoRS = .Execute
    22.    
    23.     Do While Not adoRS.EOF
    24.         Debug.Print adoRS.Fields(0).Value
    25.     Loop
    26.    
    27. End With
    28.  
    29. adoRS.Close
    30. Set adoRS = Nothing
    31. Set adoCmd = Nothing
    32. adoConn.Close
    33. Set adoConn = Nothing
    34.  
    35. End Sub

    I get an operation not allowed when object is closed error on the:

    VB Code:
    1. Do While Not adoRS.EOF

    line. Any ideas?

    Thanks!
    Last edited by Mark Gambo; May 14th, 2006 at 03:52 AM.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  2. #2

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: SPROC and VB6 Question

    BTW I am using MSSQL 2005 Database.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  3. #3
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: SPROC and VB6 Question

    I believe you need a SET NOCOUNT ON at the top of that SPROC.

    The "rows affected" messages get in the way of the returned recordset - and those INSERT's are producing that from the SPROC.

    (sorry - I think I should have mentioned that in the other thread )

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  4. #4

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: SPROC and VB6 Question

    Thanks I'll give it a try.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  5. #5

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: SPROC and VB6 Question

    Steve,
    I added the "Set NoCount On" right after the "AS" Keyword in my SPROC and it works fine now. But if I attempt to run it again I get the following T-SQL Error: "There is not enough memory to complete the task. Close down some operations and try again". Then the app closes. Any ideas?

    Here is my complete code:

    VB Code:
    1. USE IADATA
    2. IF EXISTS (select * from syscomments where id = object_id ('TestSP'))
    3.     DROP PROCEDURE TestSP
    4.  
    5. GO
    6. CREATE PROCEDURE TestSP
    7.     /*Declare Variables*/
    8.     @ListStr varchar(100) /*Hold Delimited String*/
    9. AS
    10. Set NoCount On
    11. DECLARE @ListTbl Table (InvUnit varchar(50)) /*Creates Temp Table*/
    12. DECLARE @CP int /*Len of String */
    13. DECLARE @SV varchar(50) /*Holds Result */
    14.  
    15. While @ListStr<>''
    16. Begin
    17.     Set @CP=CharIndex(',',@ListStr) /*Sets length of words - Instr */
    18.     If @CP<>0
    19.     Begin
    20.         Set @SV=Cast(Left(@ListStr,@CP-1) as varchar) /*Copies Portion of String*/
    21.         Set @ListStr=Right(@ListStr,Len(@ListStr)-@CP) /*Sets up next portion of string*/
    22.     End
    23.     Else
    24.     Begin
    25.         Set @SV=Cast(@ListStr as varchar)
    26.         Set @ListStr=''
    27.     End
    28.     Insert into @ListTbl Values (@SV) /*Inserts variable into Temp Table*/
    29. End
    30.  
    31. Select InvUnit From @ListTbl LT
    32. INNER Join dbo.Incidents ST on ST.Inv_Unit=LT.InvUnit

    and my VB6 Code:

    VB Code:
    1. Dim adoConn As ADODB.Connection
    2. Dim adoCmd As ADODB.Command
    3. Dim adoRS As ADODB.Recordset
    4. Dim strLegend As String
    5. Dim strData As String
    6.  
    7. Set adoConn = New ADODB.Connection
    8. adoConn.Open connString
    9.  
    10. Set adoRS = New ADODB.Recordset
    11. Set adoCmd = New ADODB.Command
    12.  
    13. With adoCmd
    14.     Set .ActiveConnection = adoConn
    15.     .CommandText = "TestSP"
    16.     .CommandType = adCmdStoredProc
    17.     .Parameters.Append .CreateParameter("ListStr", adVarChar, adParamInput, 100)
    18.     .Parameters("ListStr").Value = "Unit 41,Unit 32,Unit 34,Unit 54"
    19.    
    20.     Set adoRS = .Execute
    21.    
    22.     Do While Not adoRS.EOF
    23.         Debug.Print adoRS.Fields(0).Value
    24.         adoRS.MoveNext
    25.     Loop
    26.    
    27. End With
    28.  
    29. Set adoCmd = Nothing
    30. adoRS.Close
    31. Set adoRS = Nothing
    32. Set adoCmd = Nothing
    33. adoConn.Close
    34. Set adoConn = Nothing
    35.  
    36. End Sub
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  6. #6
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: SPROC and VB6 Question

    I have never seen an error like that related to SQL.

    Whenever we have issues calling a SPROC we immediately go into QUERY ANALYZER and try to duplicate the error within QA.

    In this case I would put two EXEC TESTSP lines in QA - with the two different list values being pass in.

    If the problem is with the SPROC then it will appear in QA as well.

    We have one central place in our VB code that sets parameters for calling all our SPROCS. We have DEBUG.PRINT statements in those spots so that we can see the actual values going into the parameters. We actually print them so we can COPY/PASTE them into QA - like:

    SET @LISTSTR='ABC, XYZ, SSS, TTT, VVV'

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  7. #7

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: SPROC and VB6 Question

    Back to the drawing board, Thanks Steve!
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  8. #8

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: SPROC and VB6 Question

    I had an interseting problem when I run the code on one machine which has MS Visual Studio 6.0 Pro the code fails on the second run but on another machine which has MS Visual Basic 6.0 Professional (Non-Studio) it runs fine. Hmmm, I wonder if it has anything to do with the Automation Manager?

    the investigation continues . . . . .
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  9. #9
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: SPROC and VB6 Question

    Do you have an ON ERROR GOTO XYZ error trap in that routine?

    If not put one in - and in the ERROR TRAP put a MSGBOX to look at the ERR.DESCRIPTION and stuff like that.

    Sometimes an error occurs and if not properly trapped will cause the app to run through functions and events in an unexpected fashion...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  10. #10

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: SPROC and VB6 Question

    Yep, it seems the Automation Manager is the cause of the problem. How do I go about disabling it?
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  11. #11
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: SPROC and VB6 Question

    This is the first I have heard of an automation manager...

    I google for it and it appears to be a service that you can run on a server ??

    I found this KB article...

    http://support.microsoft.com/default...;EN-US;q193238

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  12. #12

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: SPROC and VB6 Question

    Steve,

    Thanks, again!!
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  13. #13

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: SPROC and VB6 Question

    Steve,
    One more question, if I wanted to return all records or use a wildcard can I still use my SPROC or should I write another one for these types of queries?
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  14. #14
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: SPROC and VB6 Question

    We believe in using one SPROC unless there is a really good reason to have a second or third.

    Passing in two parameters should handle it.

    Change the declaration to something like this for example:

    Code:
    CREATE PROCEDURE TestSP
    	/*Declare Variables*/
    	@ListStr varchar(100) /*Hold Delimited String*/
    	@LookupValue varchar(10) /*Hold Single Lookup Value*/
    Then an IF statement to run your existing code only if @ListStr is not blank...

    Code:
    If IsNull(@ListStr,'')<>''
    Begin
    .
    .
    . all your existing code
    .
    .
    End
    Else
    Begin -- new code goes here
    Select InvUnit From dbo.Incidents
       Where InvUnit like @LookupValue+'%' or Isnull(@LookupValue,'')=''
    End
    You might not actually need the "or" statement - the Like with a blank @LookupValue will probably work fine. You can also do three different queries if you are so inclined.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  15. #15

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: SPROC and VB6 Question

    You are a magician!! Thanks. One last question (I Promise) I am still now able to get the RecordCount, I have set the CursorLocation as Client and when I try to "jiggle" the recordset like technome stated in another post I get an Run-time error '-2147217884(80040e24)'; Rowset does not support fetching backward:

    VB Code:
    1. Set adoRS = New ADODB.Recordset
    2.     With adoRS
    3.         .CursorLocation = adUseClient
    4.         .CursorType = adOpenDynamic
    5.         .LockType = adLockOptimistic
    6.      End With
    7.  
    8.  
    9.     Set adoRS = .Execute
    10.     Debug.Print adoRS.RecordCount ' <== -1
    11.     adoRS.MoveLast  '<=== Error Rowset does not support fetching backward
    12.     Debug.Print adoRS.RecordCount ' <== -1
    13.     adoRS.MoveFirst
    14.     Debug.Print adoRS.RecordCount ' <== -1

    It appears that the cursor is a Forward Only type, is this a SQL DB Permission problem or an ADO Problem?
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  16. #16
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: SPROC and VB6 Question

    Normally I live without knowing the recordcount - why do you need to know it?

    The fastest cursor type is a forward-only, read-only (I believe - I could be wrong - it's the only cursor I ever use) - so that jiggle trick won't work.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  17. #17

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: SPROC and VB6 Question

    I always thought that a For - Next Loop was faster that a Do While Loop:

    VB Code:
    1. For a = 1 to adoRS.RecordCount
    2.        'Faster
    3. Next a
    4.  
    5. Do While NOT adoRS.EOF
    6.      'Slower
    7. Loop

    Because I have been using the DoWhile Loop but I am more familiar with the For Next Style.

    Thanks again!
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  18. #18
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: SPROC and VB6 Question

    The speed difference of a loop is so meaningless compared to forcing the whole recordset to come from the client and be memory resident (or paged to local disk) just so you can MOVELAST and MOVEFIRST to get the recordcount.

    That MOVELAST operation could be noticeable to the user.

    We always choose the DO WHILE/rs.EOF technique.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  19. #19

    Thread Starter
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: SPROC and VB6 Question

    Ok, so DO While it is, Thanks again for all of your help!!!
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  20. #20
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: SPROC and VB6 Question

    No problem - glad to be of help!

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width