Connecting to MS Access 2000 DB from ASP

Posted on 2004-11-26
Last Modified: 2010-05-18
I am trying to connect to an MS Access DB from ASP and have a strange situation!

My connection string is as follows:
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=<Path to MDB>;"

I have tried the following connection strings as well, just to make sure I connect properly:
objConn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=<Path to MDB;" AND
objConn.Open "FILEDSN=<Path to DSN connection file"
The result is always the same.

After executing this statement, I check the state of the connection object. The value of
objConn.State is 1, which means the connection is open. Still, I get the following error:
Error Number: 3001
Error Description: Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
Error Source: ADODB.Connection

To further test the connection, I create a recordset object and use this connection to execute a SQL statement. The statement executes correctly and brings back results too! Now, if I check the Err object, it still gives the same error as above.

Any ideas what the error could be for and how to correct it?      
Question by:sorabharora
    LVL 11

    Assisted Solution

    probably the error object is not cleared from a previous error. try reseting the error object using Err.Clear before you try to create the new connection and then check if err.description is still set to the same value. Hope you are not using on error resume next?

    Have Fun!
    LVL 3

    Accepted Solution

    If you are using On error resume next, you can check after the connection opens for the error.  I put the sql statement into a string to it can be reported to the error page for debugging  purposes.  This is handy especially if you build them on the fly.

    Here's an example:
    On Error Resume next

    Dim DSNtemp
    Dim sqlstmt
    Set objConn = server.CreateObject("adodb.connection")

    DSNTemp = "DRIVER={Microsoft Access Driver (*.mdb)};UID=admin;"
    DSNTemp = DSNTemp & "DBQ=" & server.MapPath("yourDatabase.mdb")
    objConn.Open DSNtemp

    if err.number <> 0 then
        Response.Write("An error has occured opening the connection.<br><br>" & vbcrlf)
        Response.Write("Error Number:" & err.number & "<br>" & vbcrlf)
        Response.Write("Error Description:" & err.description & "<br>" & vbcrlf)
    end if

    Set rs = Server.CreateObject("ADODB.Recordset")

    sqlstmt = "SELECT * from YOUR_TABLE"
    Set rs = conn.execute(sqlstmt)

    if err.number <> 0 then
        Response.Write("An error has occured executing a SQL statement.<br><br>" & vbcrlf)
        Response.Write("Error Number:" & err.number & "<br>" & vbcrlf)
        Response.Write("Error Description:" & err.description & "<br>" & vbcrlf)
        Response.Write("Extra Info:  " & sqlstmt)
    end if


    Author Comment

    Hi Guys

    Thanks for your responses. I was out of office yesterday, so saw the comments just now. I did have a On Error Resume Next statement in my code. I removed that and called the page to test. It gave me a more helpful error with the line number.
    The problem was that I was trying to set the CursorLocation property for the Connection object. I guess that is not valid for Access databases. I commented that out and the problem got solved.

    Thanks for giving me the right pointer to look at!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
    This article will show, step by step, how to integrate R code into a R Sweave document
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now