Important alert: (current site time 7/15/2013 10:34:34 PM EDT)
 

VB icon

Access Connection String

Email
Submitted on: 7/30/2003 3:03:36 PM
By: Scott Bosarge  
Level: Beginner
User Rating: By 4 Users
Compatibility: ASP (Active Server Pages)
Views: 35469
 
     This code will allow you to access an MS Access database from any page in your web site regardless of the directory structure. Traditionally an include page would be written that handles the job of connecting to the database. The include file would then be referenced in all the pages where a connection was required. A connection string like this was used to connect to the database... DBName = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=./database/datafile.mdb;" This works great if you have pages only in the root web directory but no so well if your site has various directories for different content. I came up with the string below that has worked great for my applications... I hope you can put it to good use as well.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: Access Connection String
' Description:This code will allow you to access an MS Access database from any page in your web site regardless of the directory structure.
Traditionally an include page would be written that handles the job of connecting to the database.
The include file would then be referenced in all the pages where a connection was required.
A connection string like this was used to connect to the database... 
DBName = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=./database/datafile.mdb;"
This works great if you have pages only in the root web directory but no so well if your site has various directories for different content.
I came up with the string below that has worked great for my applications...
I hope you can put it to good use as well.
' By: Scott Bosarge
'
' Inputs:The only information you need to supply is the sub directory and file name of you database in this format, "subdir\dbfilename.mdb" insert your information into the "Default_DB_Path" part of the connection string below.
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=8474&lngWId=4'for details.'**************************************

<%
default_DB_Path = Request.ServerVariables("APPL_PHYSICAL_PATH") & "insert your subdir\dbfilename.mdb info here"
DBName = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & default_DB_Path & ";"
Set default_DB_conn = Server.CreateObject("ADODB.Connection")
default_DB_conn.Open DBName
%>


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

7/31/2003 2:08:27 AMShengriken

good string
(If this comment was disrespectful, please report it.)

 
6/29/2004 11:22:13 PM

very good
thangs very mach
(If this comment was disrespectful, please report it.)

 
7/6/2005 4:15:27 AM

thaks you a lot I enjoyed to your site is a good site.
I dowmloaded many programs
it is useful for students who learning IT or copmuter science
thank you.
(If this comment was disrespectful, please report it.)

 
8/10/2005 10:39:54 PMLeary Adams Tenorio

Is it goin to work when I uploaded it over a webspace (ex. WebSamba)?
(If this comment was disrespectful, please report it.)

 
4/6/2006 2:14:11 AM

Thanks you very much !
(If this comment was disrespectful, please report it.)

 
7/3/2006 5:30:35 AMyasdnil

how can i upload data from a MS Access table into a console application in vb.net
(If this comment was disrespectful, please report it.)

 
4/3/2009 2:22:26 AMEngr. Asif JAmali

I have got lot of Knowledge from this site

(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.