Basic DSN-Less Connection to DB

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.



Go Back   Webforumz.com > Main Forums > Program Your Website > Classic ASP

Notices


Closed Thread
 
LinkBack Thread Tools
  #1 (permalink)  
Old Aug 22nd, 2003, 15:19
SuperMember

SuperMember
Join Date: Aug 2003
Location: Castle Rock, CO
Age: 36
Posts: 164
Thanks: 0
Thanked 0 Times in 0 Posts
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. Thanks!

  #2 (permalink)  
Old Aug 22nd, 2003, 15:27
Highly Reputable Member
Join Date: Jul 2003
Location: Ipswich, UK
Posts: 690
Thanks: 0
Thanked 0 Times in 0 Posts
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
  #3 (permalink)  
Old Aug 22nd, 2003, 15:39
SuperMember

SuperMember
Join Date: Aug 2003
Location: Castle Rock, CO
Age: 36
Posts: 164
Thanks: 0
Thanked 0 Times in 0 Posts
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!
  #4 (permalink)  
Old Aug 22nd, 2003, 20:08
vor vor is offline
Junior Member
Join Date: Aug 2003
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
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.
  #5 (permalink)  
Old Aug 22nd, 2003, 21:08
SuperMember

SuperMember
Join Date: Aug 2003
Location: Castle Rock, CO
Age: 36
Posts: 164
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks. That seems to have fixed it. Hm, my first connection. :P I guess I am moving on up. Thanks once again!!
  #6 (permalink)  
Old Aug 23rd, 2003, 21:18
Rob's Avatar
Rob Rob is offline
Head Admin & CEO

SuperMember
Join Date: Jul 2003
Location: at my desk
Age: 34
Posts: 2,952
Blog Entries: 7
Thanks: 7
Thanked 4 Times in 4 Posts
Send a message via MSN to Rob Send a message via Skype™ to Rob
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
  #7 (permalink)  
Old Aug 28th, 2003, 13:45
Highly Reputable Member
Join Date: Jul 2003
Location: Ipswich, UK
Posts: 690
Thanks: 0
Thanked 0 Times in 0 Posts
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") & ";"

  #8 (permalink)  
Old Oct 26th, 2007, 06:08
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,608
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Send a message via Yahoo to Monie
Re: Basic DSN-Less Connection to DB

Here is the complete connection to your database including the recordset:
Code: Select all
<%
 set conn = Server.CreateObject("ADODB.Connection")
conn.Provider = "Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("fpdb/counter.mdb"))
 set rs = Server.CreateObject("ADODB.recordset")
 rs.Open "Select * from Customers", conn
%>
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)

Last edited by Monie; Oct 26th, 2007 at 06:13.
Closed Thread

Tags
basic, dsnless, connection

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT. The time now is 20:54.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43