Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Sep 2002
    Location
    Everthorpe, nr Hull, UK
    Posts
    106
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question DSN-less connection string

    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.
    Cheers

    Dean

    In the beginning god said "let there be light." and from out of the darkness a pen pusher was heard to say "not to much. that's expensive that is!"

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Cincinnati, OH
    Posts
    545
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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..

    Code:
    **********dsn.asp****************
    <%
    
    
      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 & ";"
    
      '----------------------------------------------------
    %>
    
    ***********dbpage.asp***************
    
    <%
    <!-- #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
    %>

  • #3
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Or you alternativly could do:

    Code:
    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;")
    OracleGuy

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    41 8' 52" N -95 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #5
    Regular Coder
    Join Date
    Sep 2002
    Location
    Everthorpe, nr Hull, UK
    Posts
    106
    Thanks
    0
    Thanked 0 Times in 0 Posts

    hi whammy

    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?
    Cheers

    Dean

    In the beginning god said "let there be light." and from out of the darkness a pen pusher was heard to say "not to much. that's expensive that is!"

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    41 8' 52" N -95 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •