Trying to connect to an Access db

admin

Administrator
Staff member
I can't seem to do it, here's my code:

<html>
<body>

<%
Dim adoCon 'Holds the Database Connection Object
Dim rsDb 'Holds the recordset for the records in the database
Dim strSQL 'Holds the SQL query to query the database

'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("SPD.mdb")

'Create an ADO recordset object
Set rsDb = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT tblContacts.contactName, tblContacts.telephone FROM tblContacts;"

'Open the recordset with the SQL query
rsDb.Open strSQL, adoCon

'Reset server objects
rsDb.Close
Set rsDb = Nothing
Set adoCon = Nothing

%>

</body>
</html>
It's taken pretty much directly from a tuturial website, I don't know enough about ASP to know if there's anything wrong with this.

I get the following error:

ADODB.Connection.1 error '800a0bb9'

The application is using arguments that are of the wrong type,
are out of acceptable range, or are in conflict with one another.

/database/test.asp, line 13
Any ideas on what could be wrong? I'm just trying to connect to the db, hence the lack of any code that does anything with the results, that shouldn't be the problem though. Could the server I'm using not have the proper drivers installed to do this? Line 13 is the adoCon.Open line.you can go to <!-- w --><a class="postlink" href="http://www.connectionstrings.com">www.connectionstrings.com</a><!-- w --> to see some examples of Access connection strings to use in this case.Well I'm having no luck at all. I tried all of the ones shown below. The error doesn't go away, but it changes to the following when using that last one, which I'm pertty sure I shouldn't be.

ADODB.Connection.1 error '80004005'

SQLState: IM002
Native Error Code: 0
[INTERSOLV][ODBC lib] Data source name not found and no default driver specified

/database/test.asp, line 13
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" _
& Server.MapPath("SPD.mdb")

adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" _
& Server.MapPath("SPD.mdb") & ";Uid=Admin;Pwd=;"

adoCon.Open "Driver={Microsoft Access Driver (*.mdb)};Dbq=" _
& Server.MapPath("SPD.mdb") & ";Exclusive=1;Uid=Admin;Pwd=;"

adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
& Server.MapPath("SPD.mdb") & ";User Id=admin;Password=;"

Edited for width.Just for curiousity's sake, you have done a response.write on server.mappath("spd.mdb") and verified that your .mdb file is in that location right?I tried that yeah, it seemed to path right. I tried hardcoding the path to the db just now to see if it would make a difference, but I'm getting the same error.does your web server all the use of ODBC/DSN's?

If so, then you could create one for this Access database and use that.

If this is on your local computer, you can create one through the Control PanelI only have FTP access to the server. And all I know for sure is that it supports ASP. :-/

I'll see what I can find out.Usually, when you don't have the ability to do a DSN, I'd suggest this one that you tried....

adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
& Server.MapPath("SPD.mdb") & ";User Id=admin;Password=;"


And, usually, the only thing that can go wrong with that would be a combination of a wrong Data Source location, username or password.

Do you have the ability to test this on your local machine?Hmm, well the database has no username or password. I took out the "admin" bit from that connection string but it didn't change anything.

I guess I could test it on my local machine. Do I have to do anything special to get it running correctly, or can I just run my ASP file in a browser off my hard drive?

Edit: My machine isn't set up to be any sort of server, so I'm kinda doubting I can test this.if you have Win 2000 or XP Pro, you can install IIS on your machine by going into Add/Remove Programs and clicking the button to Install/Remove Windows Componenents - IIS is an option in there.

Is that a possibility for you?I'm running Windows 2000 Professional, but I don't currently have access to a Windows CD to install the component. It is a possibility though. I may be able to get one today, I'll let you know when I do.

I'll be trying to contact the web host while I'm at it today, see if they can help me with the DNS/setting this connection up.Ok, I've got IIS installed now. Is there anything else I need to do?nope.

just get that .mdb file in some directory in your Inetpub\wwwroot directory, have an asp page that points to it and try it out.

E.G.
If you have Access file in a directory called Test under wwwroot and you create a page called test_index.asp that access it, you would type <!-- m --><a class="postlink" href="http://localhost/Test/test_index.asp">http://localhost/Test/test_index.asp</a><!-- m --> in your web browser and it, hopefully, it does what you hope it to do.Holy patatoes Batman it's working!

So I guess it's the server I'm using then. I'm still trying to get all the account information so I can call the provider and see if they can do anything about it. If not, I'll have to find another server to host this.

I'll drop by and let ya know how it's going when something... goes. Thanks for all the help.

Is IIS actually transmitting now? Are the files in wwwroot accessible through the net if someone knows my ip?

EDIT: Oh, I just found the Personal Web Manager in the Administrative Tools. Publishing is off now. :D Thanks again.
 
Back
Top