Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2004
    Posts
    75

    Exclamation Unanswered: Using a variable in a db connection string

    I would like to use a variable in my db connection string. Here is what I have:

    conn.Open "driver={Microsoft Access Driver (*.mdb)};;dbq=C:\inetpub\projects\; & 'database'"

    This does not work. "Database" is a query I am pulling from another page that is the database name with the extension. How do I put it in the connection string?

    Thanks

  2. #2
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    Soemthing more like this perhaps......
    Code:
    conn.Open "driver={Microsoft Access Driver (*.mdb)};;dbq=C:\inetpub\projects\" & database

  3. #3
    Join Date
    Apr 2004
    Posts
    75
    Quote Originally Posted by rokslide
    Soemthing more like this perhaps......
    Code:
    conn.Open "driver={Microsoft Access Driver (*.mdb)};;dbq=C:\inetpub\projects\" & database
    Tried that, still does not work. This is the error I get when I do that:
    Error Type:
    Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
    [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x304 Thread 0x61c DBC 0x2925f54 Jet'.
    /project_info.asp, line 70

    Line 70 in the db connection string...

    any other suggestions??

  4. #4
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    can you do a response.write on your connection string eg
    Code:
    response.write "driver={Microsoft Access Driver (*.mdb)};;dbq=C:\inetpub\projects\" & database 
    conn.Open "driver={Microsoft Access Driver (*.mdb)};;dbq=C:\inetpub\projects\" & database
    so we can see what is actually being built??

  5. #5
    Join Date
    Apr 2004
    Posts
    75
    that gives me the same error..

    Hmmmmm

  6. #6
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    yes, it would have given you the same error, but is should have also written out the complete connection string that you are trying to use so that you could post it here and we could see what was wrong with it.....

    I would have expected you would want something like this for you connection string
    Code:
    oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
               "Data Source=c:\somepath\myDb.mdb;"
    rather then
    Code:
    conn.Open "driver={Microsoft Access Driver (*.mdb)};;dbq=C:\inetpub\projects\" & database
    so you might want to try
    Code:
    oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
               "Data Source=c:\somepath\" & Database & ";"

Posting Permissions

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