A question about shared db connections

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

  1. #1

    Default A question about shared db connections

    Hi and Thanks in advance for taking a look at my question.

    I am using an "include" page with a sub to open a db connection for multiple
    Recordsets. My problem is that in some cases I need to use set connection
    parameters such as adOpenDynamic, adLockPessimistic, adCmdText.

    Is there a way to add these to the "Open Data Connection Command" or to the
    "Open Recordset Command"?

    Examples Follow


    **** Included File ******

    <%
    '******* Open Connection to MyData
    Sub Opendata( DatCon )
    Set DatCon = Server.CreateObject("ADODB.Connection")
    DatCon.Open "DSN=data04;"
    End Sub

    '******* Close Connection to MyData
    Sub CloseData( DatCon )
    DatCon.Close
    Set DatCon = NOTHING
    End Sub

    '******* Open Recordset from DatCon
    Sub OpenRs( Sql, rs )
    Set rs = DatCon.Execute(Sql)
    End Sub

    '******* Close Recordset from DatCon
    Sub CloseRs( rs )
    rs.Close
    Set rs = NOTHING
    End Sub

    %>


    ********** Original Page info************

    Sql = "SELECT * FROM p_CurrentUpdate WHERE CustId = " & StrCusId & " ORDER
    BY Timestamp ASC"
    OpenRs Sql, rs
    StrCurrentUpdate = "True"
    If rs.EOF Then
    StrCurrentUpdate = "False"
    Else
    rs.MoveLast
    StrCustUpdateLast = rs.Fields("Timestamp").Value
    End If
    CloseRs rs

    *******************

    When I execute this code I get [Microsoft][ODBC Microsoft Access Driver] Too
    few parameters. Expected 1.

    Now, all the Variables and Objects are "Dim" at the top of the page, and if
    I don't use the ORDER BY parameter it will work, so I am pretty sure it is
    because the proper parameters are not set for DatCon and record interaction.

    Please give any assistance you can. Thank you

    William




    William Guest

  2. Similar Questions and Discussions

    1. Shared Object question
      Hi, Thank you very much for your code! I will try your code later. May
    2. Question on Shared Files & Folders OS X -from OS X newbie
      Hi Group, I hope i am in the correct newsgroup for this question. I am a long time windows power user that has switched to OS X. I still use my 3...
    3. Question about shared hosting.
      if your server win2k, then the same asp.net process is hosting all the web sites, so all sites share the same max memory. also cross site security...
    4. Maximum connections to Win 2000 shared folder
      I have a shared folder set up on an instructor PC in a (all PCs are Win 2000) classroom. It looks like Windows will only allow me to make up to 10...
    5. (SERVER=SHARED) connections work but (SERVER=DEDICATED) does not
      All, Were running V8.1.7.4 of the database on HP-UX 11.11 I have a database setup to use MTS. The following MTS parameters are set in the...
  3. #2

    Default Re: A question about shared db connections

    William wrote:
    > Hi and Thanks in advance for taking a look at my question.
    >
    > I am using an "include" page with a sub to open a db connection for
    > multiple Recordsets. My problem is that in some cases I need to use
    > set connection parameters such as adOpenDynamic, adLockPessimistic,
    > adCmdText.
    Actually, these are recordset properties. If you set them at the Connection
    lefvel, it uses the settings for the recordsets that are created
    automatically.
    >
    > Is there a way to add these to the "Open Data Connection Command" or
    > to the "Open Recordset Command"?
    I would use them in the statement used to open the recordset. You need to
    explicitly create the recordset object and use the recordset's Open method
    to do this:

    set rs = server.createobject("adodb.recordset")
    rs.cursorlocation = adUseServer
    'or adUseClient, however, if you use this, you will only get a static cursor
    rs.cursortype = adOpenDynamic
    rs.locktype = adLockPessimistic
    'Seriously, avoid this setting in asp code! You will greatly restrict
    'your application's scalability
    rs.Open Sql,DatCon,,,adCmdText

    However, I do question the need to use anything other than the default
    forward-only cursor in asp code. Using these settings is more expensive,
    since the cursor being built needs to do more things, making it take up more
    space in memory, and making it take longer to retrieve data from the
    database.

    >
    > Examples Follow
    >
    >
    > **** Included File ******
    >
    > <%
    > '******* Open Connection to MyData
    > Sub Opendata( DatCon )
    > Set DatCon = Server.CreateObject("ADODB.Connection")
    > DatCon.Open "DSN=data04;"
    Avoid ODBC. It is obsolete. There is native OLEDB provider for Jet databases
    that offers more reliabilty and functionality than the old ODBC driver. See
    [url]www.able-consulting.com/ado_conn.htm[/url] for examples of OLEDB connection
    strings.
    >
    <snip>
    > ********** Original Page info************
    >
    > Sql = "SELECT * FROM p_CurrentUpdate WHERE CustId = " & StrCusId & "
    Avoid using "Select *" in production code. It forces ADO to make an extra
    trip to the database to change the * into an actula list of columns. It is
    best to explicitly name the columns you wish to return.
    > ORDER BY Timestamp ASC"
    <snip>
    >
    > When I execute this code I get [Microsoft][ODBC Microsoft Access
    > Driver] Too few parameters. Expected 1.
    This has nothing to do with your ADO syntax (or whether or not you are
    setting recordset cursor properties). The problem here is that "Timestamp"
    is a reserved keyword ([url]http://www.aspfaq.com/show.asp?id=2080[/url]). Your best
    course of action is to change the name of that field to a non-reserved word.
    If you cannot do that, then your only recourse is to always remember to
    surround it with brackets when you use it in queries:

    ORDER BY [Timestamp] ASC"

    HTH,
    Bob Barrows

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"


    Bob Barrows Guest

  4. #3

    Default Re: A question about shared db connections

    > course of action is to change the name of that field to a non-reserved
    word.

    Hey, that's a column, not a field. Don't make me unleash Celko on you. :-)


    Aaron Bertrand - MVP Guest

  5. #4

    Default Re: A question about shared db connections

    Aaron Bertrand - MVP wrote:
    >> course of action is to change the name of that field to a
    >> non-reserved word.
    >
    > Hey, that's a column, not a field. Don't make me unleash Celko on
    > you. :-)
    Yikes! :-)
    When talking "Access", I tend to revert to "field" rather than "column",
    since that is how Access refers to them. I know, I know .. :-)

    Bob

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"


    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