Results 1 to 3 of 3

Thread: Saving SQL stored procedure call

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Location
    Southeast Michigan
    Posts
    155

    Saving SQL stored procedure call

    I'm executing a stored procedure on a Microsoft SQL Server with something like the following code in VB6. For error trapping I test the connection prior to this to verify that it's open. If I receive any errors or if the connection is closed I have to write the data to a file to be transferred later when the connection problem is corrected. I was wondering if I could collect the data in the cmdOverride in a way that can be just the SQL command string. Then, later, read through a file that has a list of these commands and execute them without having to rebuild the stored procedure with it's text and append all the parameters again. The file could contain command strings from other stored procedures. For example, save "call dbo.sproc_cmf_override_insert1('parameter data here')", and later loop through the list of commands.

    Not sure if this is making sense?

    Code:
        
    
    On Error GoTo localErrorHandler
    
    if g_SQL_Con.State = 1 then             
        cmdOverride.ActiveConnection = g_SQL_Con
        cmdOverride.CommandType = adCmdStoredProc
        cmdOverride.CommandText = "dbo.sproc_cmf_override_insert1"
        cmdOverride.Parameters.Append cmdOverride.CreateParameter("empId", adVarChar, adParamInput, 8, g_strEmployeeNumber)
        cmdOverride.Parameters.Append cmdOverride.CreateParameter("line", adVarChar, adParamInput, 6, g_strLineNumber)
        cmdOverride.Parameters.Append cmdOverride.CreateParameter("datetime", adVarChar, adParamInput, 19, _
                        Format(Now, "MM/DD/YYYY") & " " & Format(Now, "HH:MM:SS"))
        cmdOverride.Parameters.Append cmdOverride.CreateParameter("level", adVarChar, adParamInput, 8, g_lngAuthLevel)
        cmdOverride.Parameters.Append cmdOverride.CreateParameter("text", adVarChar, adParamInput, 256, strSend)
        cmdOverride.Parameters.Append cmdOverride.CreateParameter("so", adVarChar, adParamInput, 12, "123456000001")
        cmdOverride.Parameters.Append cmdOverride.CreateParameter("steppk", adVarChar, adParamInput, 8, "9083")
        cmdOverride.Parameters.Append cmdOverride.CreateParameter("step", adVarChar, adParamInput, 8, "9083")
    
        Set rsOverride = cmdOverride.Execute
    Else
        'write command to local file
    End If
    
    Exit Sub
    
    localErrorHandler:
    
    'report message and write command to local file
    Dave

    Helpful information I've found here so far : The Definitive "Passing Data Between Forms" : Restrict TextBox to only certain characters, numeric or symbolic :
    .NET Regex Syntax (scripting) : .NET Regex Language Element : .NET Regex Class : Regular-Expressions.info
    Stuff I've learned here so far : Bing and Google are your friend. Trying to help others solve their problems is a great learning experience

  2. #2
    Frenzied Member
    Join Date
    Dec 2014
    Location
    VB6 dinosaur land
    Posts
    1,190

    Re: Saving SQL stored procedure call

    Seems feasable as long as you don't have any security concerns. Technically, anyone would then be able to edit your file with whatever commands they wished. If it is a concern then I would save what you need to call the same routine that calls the stored procedure along with setting the variables needed as parameters. You'd have to refactor to handle the Now function.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Location
    Southeast Michigan
    Posts
    155

    Re: Saving SQL stored procedure call

    I think I've just resolved the issue with some testing. Instead of setting the command type to adCmdStoredProc I will do something like the following:
    Code:
    Dim commandString as string
    
    On Error GoTo localErrorHandler
    
    if g_SQL_Con.State = 1 then             
        cmdOverride.ActiveConnection = g_SQL_Con
        commandString = "{ call dbo.sproc_cmf_override_insert1(" & _
            Employee_Number & "," & _
            Line_Number & "," & _
            Date_Time & "," & _
            Auth_Level & "," & _
            Text_To_Send & "," & _
            Shop_Order_Number & "," & _
            PK_Step_Number & "," & _
            Step_Number & ") }"
    
        cmdOverride.CommandText = commandString
        Set rsOverride = cmdOverride.Execute
    Else
        'write command to local file
    End If
    
    Exit Sub
    
    localErrorHandler:
    
    'report message and write command to local file
    Then write the variable commandString to a file for later processing if required. That way I won't have to decipher which sproc I'm calling from the routine that checks this file for data. Just open it and loop through each line, set the command string and execute. If security is an issue I can encrypt the data.

    At least I think that will work ok.
    Dave

    Helpful information I've found here so far : The Definitive "Passing Data Between Forms" : Restrict TextBox to only certain characters, numeric or symbolic :
    .NET Regex Syntax (scripting) : .NET Regex Language Element : .NET Regex Class : Regular-Expressions.info
    Stuff I've learned here so far : Bing and Google are your friend. Trying to help others solve their problems is a great learning experience

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