connect to a database

Discussion in 'ASP General' started by Peter Morris, Jun 29, 2003.

  1. Peter Morris

    Peter Morris Guest

    Newbie question, I'm just learning ASP

    I am having trouble connecting to a database. I have set up the
    ODBC data source Northwind to link to the Northwind database.

    Now, I'm running the following script:

    <% @language = vbscript %>
    <%
    Option explicit
    Response.expires = 0
    dim objConn, objRS, strQuery
    dim strConnection
    Set ObjConn = server.createObject("ADODB.connection")
    strConnection = "DSN=Northwind;database=northwind;"
    strConnection = strConnection & "UID=sa;PWD=;"
    objConn.open strConnection
    ....
    %>

    This produces the following error:

    Error Type:
    Microsoft OLE DB Provider for ODBC Drivers (0x80040E4D)
    [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user
    'YOUR-D10B605044\IUSR_YOUR-D10B605044'.
    /asp24/hour13/readdata.asp, line 10


    Why is this happening? Why can't I connect?

    Note - there doesn't seem to be anything wrong with the database or the
    DSN. I have created a visual basic program which successfully opens
    and reads the same database and DSN. This connects like so:

    Dim cnn1 As ADODB.Connection
    Dim rstRec As ADODB.Recordset
    Dim strCnn As String

    Sub main()
    Set cnn1 = New ADODB.Connection
    strCnn = "DSN=Northwind;Database=Northwind;UID=sa;PWD=;"
    cnn1.Open strCnn
    End Sub

    Why does it work in visual basic, but not in VBScript? Is there
    perhaps something I must configure in IIS for it to work, or something
    like that?

    --
    _______________________
    /_____________________(_)
    | ______________________ email to
    | | |__________________(_) Peter_Morris_1 at
    | |/____________________ btinternet dot com
    |_____________________(_)
     
    Peter Morris, Jun 29, 2003
    #1
    1. Advertisements

  2. Peter Morris

    Robb Meade Guest

    ...
    Welcome aboard - tickets please :eek:)
    hmm...I've not used ASP and Access databases together, usually SQL, so I'm
    not sure if I can be much help...

    Couple of things to check,

    I took this :

    Access connection string looks like this;
    "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Temp\Northwind.mdb"

    from

    http://www.tek-tips.com/gfaqs.cfm/lev2/4/lev3/31/pid/333/fid/178

    and also this:

    A typical connection string for the Access Northwind database is:
    "provider=Microsoft.Jet.OLEDB.4.0; data source=YourPath\Northwind.MDB"

    from

    http://msdn.microsoft.com/library/d...y/en-us/dv_vstechart/html/jstchdataadonet.asp


    again, I've not connected into an Access database from ASP before, but the
    connection string would be the first thing I'd look at.

    Followed by double checking the username/password - as the error message
    does suggest a login problem.

    And also the permissions on the directory that the access database is stored
    in, if you plan to write to the database I think you'll need to enable the
    'write' permission from the ISM within IIS (I might be wrong).

    Good luck!

    Robb
     
    Robb Meade, Jun 29, 2003
    #2
    1. Advertisements

  3. Peter Morris

    Robb Meade Guest

    Robb Meade, Jun 29, 2003
    #3
  4. Peter Morris

    Peter Morris Guest

    Thanks. one of the links you provided gave the correct connection string,
    which is:


    strConnection = "Driver={SQL Server}; Server=(local); Database=Northwind;
    UID=sa; PWD=;"
     
    Peter Morris, Jul 2, 2003
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.