View Full Version : DSN-less connection string

02-18-2003, 02:44 PM
hi there

I have a access2000 database popmanager.mdb that is in the same folder as the asp pages that are using it.

can some give me an example of a dsnless connection string so that i make this folder self contained and this way make the asp and the dynamic pages that run from it moveable from site to site.
without the need for having dsn's sett p every time i move the folder.

all help welcome as my brain died during the night and the surgeons are still operating to get it back up and running.
:confused: :confused: :confused:

02-18-2003, 03:21 PM
It has been forever since I used this script but it should still work. I usually just save this snippet as dsn.asp and include it on the pages I need..


Dim sDB, sPath, sDSNDir, sDSNFil, sDefDir, sDSN, sScriptDir

' This is the entire DB path - Physical with respect to root physical path
sDB = "WorkRequest.mdb"

' DO NOT Edit the entries below

' Retrieve the script directory
sScriptDir = Request.ServerVariables("SCRIPT_NAME")
sScriptDir = StrReverse(sScriptDir)
sScriptDir = Mid(sScriptDir, InStr(1, sScriptDir, "/"))
sScriptDir = StrReverse(sScriptDir)

' Set the virtual Directory
sPath = Server.MapPath(sScriptDir) & "\"

' This is the DSN file Name for Access database
sDSNFil = "Access.dsn"

' This is the resulting DSN string
sDSN = "filedsn=" & sPath & sDSNFil & ";DefaultDir=" & sPath & ";DBQ=" & sPath & sDB & ";"



<!-- #include file="Dsn.asp" -->
Set rsPrnt = Server.CreateObject("ADODB.RecordSet")
sSQL = "SELECT PINumber FROM ISApproval WHERE PINumber ='" & Request.Form("txtPrntNumb") & "'"
rsPrnt.Open sSQL, sDSN, adOpenStatic, adLockOptimistic

02-18-2003, 11:26 PM
Or you alternativly could do:

Set DataConn = Server.CreateObject("ADODB.Connection")
'Open the connection
DataConn.Open "DBQ=" & Server.MapPath("yourdb.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};"

'Open a recordset
Set rs = DataConn.Execute("SELECT * FROM MyTable;")

02-19-2003, 01:27 AM
Not a good idea to store the database in the same folder as the pages that are using it - that allows someone to download your entire database if they can guess the name, or successfully perform a SQL Injection attack.

I would store your folder in the same "space" as your root directory, so it cannot be accessed from the internet, the way brinkster.com does it.


02-19-2003, 11:33 AM
i have developed a dynamic popup management booth that allows you to control and generate popups on a site by simply adding three lines of code to the pages that will fire the popup and everything else is run from a single folder.

the three lines of code are a set session with the id of the page then a 1x1 iframe that pulls a page which checks the session for the page id then checks into the database to see if there are any popups set to appear on the page. if there are the page will check the cookie folder to see if this popup has been seen and then check the date of the cookie and see if it within the do not show period for the popup. if the popup is good to go it popup and then write a cookie saying ive been shown. then it will then check the next popup to see if can go and so on.

so if i have 3 popups for the home page but one is to be shown once a week so not to annoy the user and 1 is set for 3 days and the other for 1 day. on the first day you will see all 3 the next only 1 then once 3 days has gone by you will see 2 and once a week has gone by you will the third one again and then not for another week.

Because this page is hidden away in a 1x1 iframe the page it is on loads first and then this goes on behind it.

The reason for using the ifram to run the popup generator code. is that if you have the same popup on three pages it will only appear on the first page you open not the other so saves hitting the user with the same popup which can be annoying.

the system uses three asp pages that are displayed as different types of popup on for flash popups one for text and images popups and one for dynamically linked popups for if the site has a dynamic press centre or articles database. these pages size location and content is all run form the database so they can be made to appear and disappear at will from the popup management booth.

to make a new popup you simply type in the size and location the time period for the cookie and info you want to appear on the popup if it flash you simply put the url of the swf the same for the images and input the text you want to appear and the url for the link on the popup.

Using asp upload to upload the images and swfs strait from into the booth form the booth means everything can be doen in seconds to put a popup on a page. and simply a click to delete it.

Atthe moment i am running this system on one of my customers site using sql2000 to run the whole thing off.

What i am trying to do if i can get this dns-less contection to work is make a flat pack version running of an access database then the whole thing can be dropped into a site the same way that would with a snitz forum simply unzip into the desired location upload your logo and then start typing in your page names and it will give you the code to stick on the page. then once you have the 3 lines of code in place you can start maing popups to your hearts content.

the problem being is that I use dsn's for access and dsn-less connection string for sql which run server to server using the machine name. i can't remember ever actually needing to use an access databse with a dsn-less string till now.

So what do you think?

02-20-2003, 01:00 AM
I still think you should store your database above the root directory; but for a simple dsnless connection, I use this:

sConnString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
Mid(Server.MapPath("\"), 1, InStrRev(Server.MapPath("\"),"\")-1) & "\database\dbname.mdb;" & _
"Persist Security Info=False;"

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open sConnString

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum