This is a discussion on "Basic DSN-Less Connection to DB" within the Classic ASP section. This forum, and the thread "Basic DSN-Less Connection to DB are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Basic DSN-Less Connection to DB
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
Basic DSN-Less Connection to DB
OK - VERY new to ASP. I thought that I could build a connectoin to the Database but I always got an error. I have a file in the database folder & then I have another folder - called count. Both of these are in the root. The db is called counter & the table is hit_count & the filed name is hit_count. I created a few different scenarios, but it did not work. Any suggestions? I searched thru www.asp101.com & a few others but nothing I saw was REALLY basic that I needed.
|
|
|
|
|||
|
Hi Corey,
Please could you post the error message? If you need help with connection strings, look here: http://webforumz.com/topic.asp?TOPIC_ID=8 Cheers, Smokie |
|
|||
|
Well the error message is:
Microsoft OLE DB Provider for ODBC Drivers error '80004005' [Microsoft][ODBC Microsoft Access Driver] '(unknown)' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides. /counter/default.asp, line 13 Actually the db is in fpdb - has writeable permissions, etc. This is what I am using: <% 'DSN Less Coneection to the Database strDBPath = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=fpdb/counter.mdb" ' Create an ADO Connection to connect to the database. Set cnnSimple = Server.CreateObject("ADODB.Connection") ' This line is for the Access sample database: cnnSimple.Open strDBPath ' Execute a query using the connection object. It automatically ' creates and returns a recordset which we store in our variable. Set rstSimple = cnnSimple.Execute("SELECT * FROM TestTable") ' Display a table of the data in the recordset. We loop through the ' recordset displaying the fields from the table and using MoveNext ' to increment to the next record. We stop when we reach EOF. %> And line 13: cnnSimple.Open strDBPath I know it is in the fpdb/counter - I am sure. Plus to read the value from the table - I am using: <%= rstSimple.Fields("hit_count").Value %> - not too sure if that is correct since it has not gotten that far either. Thanks! |
|
|||
|
The Path to the database has to be the Physical Path, ie. c:\Db.mdb and not a Relative path ie. folder/db.mdb, which you seem to have used.
|
|
|||
|
Thanks. That seems to have fixed it. Hm, my first connection. :P I guess I am moving on up. Thanks once again!!
|
|
||||
|
It's worth also pointing out you could have used this:-
strDBPath = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & server.mappath("fpdb/counter.mdb") :wink:
__________________
Rob - SEO Specialist Owner & Founder of Webforumz.com I am currently unavailable for private work
Last Blog Entry: Creative Labs threaten developer over home made drivers.... (Apr 1st, 2008)
|
|
|||
|
strDBPath = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=fpdb/counter.mdb"
BTW the old access driver sucks, you should use Jet, it'll give you nicer error messages and better performance: strDBPath = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("fpdb/counter.mdb") & ";" |
|
|||
|
Re: Basic DSN-Less Connection to DB
Here is the complete connection to your database including the recordset:
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
Last edited by Monie; Oct 26th, 2007 at 06:13. |
![]() |
| Tags |
| basic, dsnless, connection |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Asp to MSAcess connection? | tolis | Classic ASP | 6 | Oct 19th, 2007 07:12 |
| PHP n MySQL connection | uddin | PHP Forum | 1 | Apr 18th, 2007 06:41 |
| DB connection problem | Strike | Classic ASP | 1 | Jul 4th, 2006 09:45 |
| Connection String DSN-less | gwx03 | Classic ASP | 11 | Nov 26th, 2003 12:07 |
| dns less connection String | djaccess | Classic ASP | 7 | Oct 5th, 2003 14:34 |