SQL OLEDB - Timout Problem w/ Particular Statement

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default SQL OLEDB - Timout Problem w/ Particular Statement

    Hello

    In my ASP page I am trying to ascertain whether a randomly generated ID starts with certain characters that are not allowed or has been used before.

    When the SQL statement for latter is executed I get:

    Microsoft OLE DB Provider for SQL Server error '80040e31'

    Timeout expired

    /Admin/Start2WaySMS.asp, line 52

    This is most bizarre because I have already executed two SQL statements prior to this on the same connection object, both of which execute successfully.

    Also, this is only happening on my production server and not my staging server. Both servers are at the same MDAC revision and SQL Server 2000 SP3.

    This is the ASP code that is being executed:

    bSessionIDOK = False

    Do While Not bSessionIDOK

    stSessionID = Generate2WaySessionID

    If objConn.Execute("SELECT Keyword FROM dbo.tblReservedKeywords WHERE (Keyword = " & DbString(Left(stSessionID, 2)) & ")", , adCmdText).EOF & _
    And objConn.Execute("SELECT SessionID FROM dbo.tbl2WaySessions WHERE (SessionID = " & DbString(stSessionID) & ")", , adCmdText).EOF & _
    Then bSessionIDOK = True

    Loop

    The line that reports the error is where the second statement is executed.

    I have watched this execute using SQL Profiler and nothing untoward is reported, save a sp_reset_connection immediately after the second statement appears. Most statements have about four lines in profiler that have the same text and different event classes. e.g. SQL:BatchStarting, SQL:StmtStarting, SQL:StmtCompleted and SQL:BatchCompleted. All that is reported for the statement in error is: SQL:BatchCompleted, Attention and RPC:Completed.

    Naturally, I have run the statements themselves in Query Analyzer and they both execute with no problems. One thing I should mention is that there are no records in tbl2WaySessions. (I know that if I was using a stored procedure I would get a closed recordset, not EOF.)

    I have also changed my code to assign the objConn.Executes to recordset variables and then test their EOFs (closing the first one before opening the second) and exactly the same thing happens.

    I have run sp_Who2 and there is no blocking.

    I am sure I have missed something stupid but cannot figure it out. Any help would be much appreciated.

    David M

    P.S. Apologies for posting in HTML but I am using Outlook Express and I know a plain text version will also be available for those with down-level news readers and those accessing via a website. Hopefully this will be more readable for those viewing this with software released this century.

    David Morgan Guest

  2. Similar Questions and Discussions

    1. OleDb May Cause A Problem?
      Hi all folks, I wrote simple code like that: try { //oleDbConnection1.="Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet...
    2. Problem with Sql statement?
      I have the following Sql query: SELECT * from vendor left outer join model on vendor.PID=model.VendorID left outer join specs on...
    3. Dreamweaver ASP.NET OLEDB connection problem
      have some Dreamweaver ASP .NET OLE DB connectin problem - I have "The connection was made susessfull" message but doesn't see any table in it. Can...
    4. ATA harddrive sleep/spindown timout?
      Hello Heikki: I stumbled on this post by you - but not resolving answers - I have the same question? Did you find good answers for FreeBSD? ...
    5. Problem with OLEDB over ODBC
      I have an asp page used to access data from an access database. When I use the following as connection string (OLEDB)...
  3. #2

    Default Re: SQL OLEDB - Timout Problem w/ Particular Statement

    I suggest converting this to a stored procedure. Your code is very
    inefficient:
    1. you make two trips to the database where one will do.
    2. You have two recordsets being returned to your page, either of which
    could contain some amount of data, which you don't even intend to use.

    Personally, I would create a stored procedure with an output parameter,
    however, I don't have time to illustrate how to do it now, so I will show
    you a stored procedure that returns a recordset containing the result of the
    test:

    CREATE PROCEDURE KeywordExists (
    @word varchar(30)) AS
    IF EXISTS (Select * FROM dbo.tblReservedKeywords WHERE Keyword = Left(@word,
    2))
    AND EXISTS
    (Select * FROM dbo.tbl2WaySessions WHERE SessionID = @word)
    Select 1 KeywordExists
    Else
    Select 0 KeywordExists


    In ASP:
    bSessionIDOK = False
    Do While Not bSessionIDOK
    stSessionID = Generate2WaySessionID
    set rs=server.createobject("adodb.recordset")
    objConn.KeywordExists stSessionID, rs
    If rs(0).value = 0 Then bSessionIDOK = True
    rs.close
    set rs = nothing
    Loop

    HTH,
    Bob Barrows


    "David Morgan" <david@davidmorgan.me.uk> wrote in message
    news:O62HJiEiDHA.1952@TK2MSFTNGP10.phx.gbl...
    Hello
    In my ASP page I am trying to ascertain whether a randomly generated ID
    starts with certain characters that are not allowed or has been used before.
    When the SQL statement for latter is executed I get:
    Microsoft OLE DB Provider for SQL Server error '80040e31'
    Timeout expired
    /Admin/Start2WaySMS.asp, line 52
    This is most bizarre because I have already executed two SQL statements
    prior to this on the same connection object, both of which execute
    successfully.
    Also, this is only happening on my production server and not my staging
    server. Both servers are at the same MDAC revision and SQL Server 2000 SP3.
    This is the ASP code that is being executed:
    bSessionIDOK = False
    Do While Not bSessionIDOK
    stSessionID = Generate2WaySessionID
    If objConn.Execute("SELECT Keyword FROM dbo.tblReservedKeywords WHERE
    (Keyword = " & DbString(Left(stSessionID, 2)) & ")", , adCmdText).EOF & _
    And objConn.Execute("SELECT SessionID FROM dbo.tbl2WaySessions WHERE
    (SessionID = " & DbString(stSessionID) & ")", , adCmdText).EOF & _
    Then bSessionIDOK = True
    Loop
    The line that reports the error is where the second statement is executed.
    I have watched this execute using SQL Profiler and nothing untoward is
    reported, save a sp_reset_connection immediately after the second statement
    appears. Most statements have about four lines in profiler that have the
    same text and different event classes. e.g. SQL:BatchStarting,
    SQL:StmtStarting, SQL:StmtCompleted and SQL:BatchCompleted. All that is
    reported for the statement in error is: SQL:BatchCompleted, Attention and
    RPC:Completed.
    Naturally, I have run the statements themselves in Query Analyzer and they
    both execute with no problems. One thing I should mention is that there are
    no records in tbl2WaySessions. (I know that if I was using a stored
    procedure I would get a closed recordset, not EOF.)
    This is incorrect.


    Bob Barrows Guest

  4. #3

    Default SQL OLEDB - Timout Problem w/ Particular Statement

    For even more efficiency, would it be possible to put the
    code that generates the random ID into the stored
    procedure so that you're not making all the trips to the
    database that this loop may require?

    Bob Barrows
    >-----Original Message-----
    >
    > Do While Not bSessionIDOK
    >
    > stSessionID = Generate2WaySessionID
    Bob Barrows Guest

  5. #4

    Default Re: SQL OLEDB - Timout Problem w/ Particular Statement

    Hi Bob

    Thanks for your most hasty response, it is much appreciated.

    Whilst your performance optimisations are noted I am afraid that doesn't
    actually help me with this exact problem.

    It is the most bizarre thing I have ever seen.

    My next step was to create a stored procedure which just did a check for
    EXISTS on the @Word. This too returned timeout expired whilst the
    previous statement, (checking the reserved words table), executes with
    no problem.

    So I stepped even further back and just did a SELECT * FROM table in a
    completely new ASP. This too returns me Timeout Expired as per the
    previous attempts.

    Here is the code for this new page:

    ------------------------------------------------------------
    <% Option Explicit
    Dim objConn, objRs
    Set objConn = Server.CreateObject("ADODB.Connection")
    objConn.Open Application("Database_ConnectionString")
    Set objRs = objConn.Execute("SELECT * FROM dbo.tbl2WaySessions")
    If Not objRs.EOF Then
    Do While Not objRs.EOF
    Response.Write "<p>" & objRs.Fields(0).Value
    objRs.MoveNext
    Loop
    End If
    objRs.Close
    'Response.Write "<p>" & objConn.Execute("EXEC usp_IsUniqueSessionID
    '36B4PS3293I00NYQ'").Fields(0).Value
    objConn.Close
    Set objConn = Nothing %>
    ------------------------------------------------------------

    Now whilst this again might be inefficient, I am starting to really
    loose my marbles with this problem.

    As previously stated, the connection string is being used on 100 other
    pages with no problems.

    Again, any help would be most welcomed.

    Regards

    David M


    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    David Morgan Guest

  6. #5

    Default Re: SQL OLEDB - Timout Problem w/ Particular Statement

    You may be running into something called "parameter sniffing". Here is a
    good explanation of it:
    [url]http://tinyurl.com/h7aa[/url]

    You should use Profiler to see if a different execution plan for your query
    is used when calling it from asp and when calling it from QA. This will be a
    pretty good indication that you need to take the steps suggested in the
    link.

    Bob Barrows

    David Morgan wrote:
    > Hi Bob
    >
    > Thanks for your most hasty response, it is much appreciated.
    >
    > Whilst your performance optimisations are noted I am afraid that
    > doesn't actually help me with this exact problem.
    >
    > It is the most bizarre thing I have ever seen.
    >
    > My next step was to create a stored procedure which just did a check
    > for EXISTS on the @Word. This too returned timeout expired whilst the
    > previous statement, (checking the reserved words table), executes with
    > no problem.
    >
    > So I stepped even further back and just did a SELECT * FROM table in a
    > completely new ASP. This too returns me Timeout Expired as per the
    > previous attempts.
    >
    > Here is the code for this new page:
    >
    > ------------------------------------------------------------
    > <% Option Explicit
    > Dim objConn, objRs
    > Set objConn = Server.CreateObject("ADODB.Connection")
    > objConn.Open Application("Database_ConnectionString")
    > Set objRs = objConn.Execute("SELECT * FROM dbo.tbl2WaySessions")
    > If Not objRs.EOF Then
    > Do While Not objRs.EOF
    > Response.Write "<p>" & objRs.Fields(0).Value
    > objRs.MoveNext
    > Loop
    > End If
    > objRs.Close
    > 'Response.Write "<p>" & objConn.Execute("EXEC usp_IsUniqueSessionID
    > '36B4PS3293I00NYQ'").Fields(0).Value
    > objConn.Close
    > Set objConn = Nothing %>
    > ------------------------------------------------------------
    >
    > Now whilst this again might be inefficient, I am starting to really
    > loose my marbles with this problem.
    >
    > As previously stated, the connection string is being used on 100 other
    > pages with no problems.
    >
    > Again, any help would be most welcomed.
    >
    > Regards
    >
    > David M
    >
    >
    > *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    > Don't just participate in USENET...get rewarded for it!


    Bob Barrows Guest

  7. #6

    Default Re: SQL OLEDB - Timout Problem w/ Particular Statement

    David Morgan wrote:
    >
    > So I stepped even further back and just did a SELECT * FROM table in a
    > completely new ASP. This too returns me Timeout Expired as per the
    > previous attempts.
    Oh wait. No parameters? And it times out? That obviously can't be due to
    parameter sniffing.
    >
    > Here is the code for this new page:
    >
    > ------------------------------------------------------------
    > <% Option Explicit
    > Dim objConn, objRs
    > Set objConn = Server.CreateObject("ADODB.Connection")
    > objConn.Open Application("Database_ConnectionString")
    > Set objRs = objConn.Execute("SELECT * FROM dbo.tbl2WaySessions")
    You said there are no records in this table, right? And you've checked
    sp_who (or better sp_who2) to verify that no blocking is occurring ...

    Is the problem table-specific? Does it occur when you select records from
    other tables?

    Bob Barrows



    Bob Barrows Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139