Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 11th, 2006, 07:41 AM
Registered User
 
Join Date: Oct 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is the parts of my code that I think are causing the problems. If you need more info, please let me know.

Private Sub cmdRun_Click()

Dim strMonth As String
Dim strYear As String
Dim strBeginDate As String
Dim strEndDate As String
Dim lngTotal As Long 'Running total of pages
Dim strNum As String
Dim validYear As Boolean
Dim result As String


    validYear = Year_Validate 'Validates that month textbox has four digit year

    If validYear = True Then
        'lblError = ""
         strMonth = lstMonth.ListIndex

        If strMonth = -1 Then
            lblError = "Please select a month"
            Exit Sub
        ElseIf Len(strMonth) = 1 Then
            strMonth = "0" & lstMonth.ListIndex
            lblError = ""
            strYear = txtYear.Text
        Else
            strMonth = lstMonth.ListIndex
            lblError = ""
            strYear = txtYear.Text
        End If

        strBeginDate = strYear & "-" & strMonth & "-01"
        strEndDate = strYear & "-" & strMonth & "-31"


        result = runQuery(strBeginDate, strEndDate)
        lngTotal = CLng(result)
        txtResults.Text = "Scanned & Imported Count: " & Format(lngTotal, "###,###,###") & " pages"
    Else
        Exit Sub
    End If

    StatusBar1.Panels(1).Text = "Finished wirh page count!"

Exit Sub

End Sub

-----------------------------------------

Public Function runQuery(strBeginDate As String, strEndDate As String) As String
   On Error GoTo QueryError

    runQuery = ""

    If cnServer.State = adStateClosed Then
        Set cnServer = New ADODB.Connection
            With cnServer
                    .ConnectionString = "Provider=SQLOLEDB;" & _
                                                 "INITIAL CATALOG=ESWM41;" & _
                                                 "USER ID=EISROBOT;" & _
                                                 "PASSWORD=ROBOT;" & _
                                                 "DATA SOURCE=SQLSERV"
                    .ConnectionTimeout = 1500
                    .CursorLocation = adUseClient
                    .CommandTimeout = 2000
                    .Open
            End With
    End If

    Set rsServer = New ADODB.Recordset

    With rsServer
            .ActiveConnection = cnServer
            .CursorType = adOpenStatic
    End With

    createParams

    cmdPageCount.CommandText = "select sum (cast(right(object_name,3)as int)) " _
               & "From Attributes " _
               & "Where ix_receive_date >= ? " _
               & "And ix_receive_date <= ? " _
               & "and object_class <> 'images' " _
               & "and fv_scan_data not in " _
                    & "(select fv_scan_data " _
                     & "From Attributes " _
                     & "Where object_class = 'images' " _
                     & "and ix_receive_date >= ? " _
                     & "and ix_receive_date <= ? )"

    cmdPageCount(0) = strBeginDate
    cmdPageCount(1) = strEndDate
    cmdPageCount(2) = strBeginDate
    cmdPageCount(3) = strEndDate

    StatusBar1.Panels(1).Text = "Processing Query"
    Set rsServer = cmdPageCount.Execute

    runQuery = rsServer.GetString

    If rsServer.State = adStateOpen Then
        rsServer.Close
    End If

    If cnServer.State = adStateOpen Then
        cnServer.Close
    End If

    Set rsServer = Nothing
    Set cnServer = Nothing

QueryError:
    MsgBox Err.Description & Err.Source
    Exit Function

End Function


Private Sub createParams()
    Set cmdPageCount.ActiveConnection = cnServer
    cmdPageCount.CommandType = adCmdText
    cmdPageCount.Prepared = True

    Set prmOuterBeginDate = cmdPageCount.CreateParameter(, adChar, adParamInput, 10)
    cmdPageCount.Parameters.Append prmOuterBeginDate

    Set prmOuterEndDate = cmdPageCount.CreateParameter(, adChar, adParamInput, 10)
    cmdPageCount.Parameters.Append prmOuterEndDate

    Set prmInnerBeginDate = cmdPageCount.CreateParameter(, adChar, adParamInput, 10)
    cmdPageCount.Parameters.Append prmInnerBeginDate

    Set prmInnerEndDate = cmdPageCount.CreateParameter(, adChar, adParamInput, 10)
    cmdPageCount.Parameters.Append prmInnerEndDate

    paramsCreated = True
End Sub


 
Old October 11th, 2006, 07:52 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

What happens if you execute the query as a stored procedure?

--Stole this from a moderator

I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
 
Old October 11th, 2006, 07:57 AM
Registered User
 
Join Date: Oct 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

We are not to use stored procedures. We are supposed to keep everything in prepared statements, as it is now. Do you think that the prepared statements could have something to do with it?

 
Old October 11th, 2006, 08:12 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

To be 100% honest with you, I do not use prepared statements like you do above since that is only good to execute one certain query; I use a wrapper class that I can send any sql command to and have a result returned to my applications (if the query is to return a resultset obviously).

In any case it has been a long time since I have looked at VB code prior to .NET so I may be a little rusty, but, your params you setup as input params, length of 10 but I don't see where you supply a variable to the parameter itself.

In .NET a parameterized query looks something like this:
SELECT * From table Where valuea = @value1 AND valueB = @valueB

our command object would then look like this:

objCommand.Parameters.Add("@value1", txtValueA.text) 'You can also supply the DBType, length, etc as an overload
objCommand.Parameters.Add("@value2", txtValueB.text)

I see where you have added your parameters, their types and such, but I don't see where you point it to a physical value?

--Stole this from a moderator

I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
 
Old October 11th, 2006, 01:44 PM
Registered User
 
Join Date: Oct 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks everybody. I figured it out. I had to add above the 'cmdPageCount.CommandText', cmdPageCount.CommandTimeout = 0. I appreciate the help and knowledge on this problem.

 
Old October 11th, 2006, 10:03 PM
SQLScott's Avatar
Wrox Author
 
Join Date: Dec 2004
Posts: 338
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Yeah, after looking at your code (sorry, was just getting around to looking at it), you were setting the timeout on the connection itself and not on the command object.

Glad you got it working.

Scott Klein
Author - Professional SQL Server 2005 XML
http://www.wrox.com/WileyCDA/WroxTit...764597922.html
 
Old October 16th, 2006, 11:48 PM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

Bob,

You might want to run a security analyzer program against all that embedded SQL... looks like an SQL INJECTION attack just waiting to happen... that's the reason why most folks use stored procs... they're one of the first lines of defense against SQL INJECTION...

--Jeff Moden
 
Old October 17th, 2006, 10:24 AM
Registered User
 
Join Date: Oct 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

First of all, thanks ScottSQL for the comment. Next, Mr.Moden, I'm not quite picking up on the SQL Injection. Can you explain that a little further? Since it was only one query in my application, I saw no reason for prepared statements, but I guess you do what you are told in the workplace for the most part. Anyway, if you will, could you please give me some info on SQL Injection? It would be much appreciated!!

 
Old October 17th, 2006, 10:29 AM
SQLScott's Avatar
Wrox Author
 
Join Date: Dec 2004
Posts: 338
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Hi Bob,

In Books Online, look up SQL injection. there is a great explanation on what that is.

Scott Klein
Author - Professional SQL Server 2005 XML
http://www.wrox.com/WileyCDA/WroxTit...764597922.html





Similar Threads
Thread Thread Starter Forum Replies Last Post
TIP: Redirecting when session expires jimibt BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 5 November 16th, 2007 05:42 AM
Page Expires on hitting backspace. nishant_611 Apache Tomcat 0 May 9th, 2007 01:19 AM
Session expires immediately codebuyer Classic ASP Components 6 March 18th, 2005 12:54 PM
page expires isheikh BOOK: Beginning ASP 3.0 1 May 31st, 2004 11:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.