Page 303 - DCAP408_WEB_PROGRAMMING
P. 303

Unit 14: Database Connectivity




              Click “Add” to add a DSN less entry, and then on “Microsoft Access Drive”. If “Microsoft  Notes
               Access Driver” does  not appear  on the list, you possibly have  not installed Microsoft
               Access 7’s, 32 bit ODBC drivers.
              At the “Data Source Name” enter “UserDB1”, then “Select” the database - you can use
               “Browse” to select the database users.mdb. With “users” directory created for the application
               the path to the database c:\inetsrv\wwwroot\users\users.md

          Connecting to the Database - Method

          This is done to maintain a connect throughout the user’s session. The connection is closed when
          the session ends. This is controlled by the Global.asa file. Each ASP-Based intranet application
          can have one global.asa file located in the root directory of the application. The global.asa has
          four events - Application-Start , Session-Start, Application-End and Session-End. The connect to
          the database for the session is in the Session-Start event , with Session-End being the event used
          to close the connection.


               !
             Caution  The language or script being used is VBScript and the ASP is to run on the server.
          Connect string in Global.asa
          Conn.Open “UserDB1”, “userdblogin”,”userdbpassword”

          “Conn” is connect to the database that can be used throughout the session to the DSN less entry
          UsersDB1 with a login of “userdblogin” and a password of “userdbpassword”.
          The first post-startup request is made to the web server for any *.asp file in an application causes
          the Global.asa to be read. So the moment a request is made to any *.asp in the directory in which
          the intranet application is stored a connection is established with the DSN less UserDB1. Following
          that the default document, in this case default.asp is processed.


                 Example: Connecting to database method
          SUB Session_OnStart
          ‘—— Open ADO connection to database
          Conn.Open “UsersDB1”, “userdblogin”,”userdbpassword”

          END SUB

          14.1.1 DSN  Less

          Requires no server setup, just a carefully constructed connection string as demonstrated below.
          DSN less connections demand that that you know the name of the file (i.e. file based databases
          like Access, Paradox, FoxPro, etc.) or the address of the data server (SQLserver, for example).
          Armed with appropriate information you could open a data source without a DSN!  This is faster
          than a system DSN* since it saves a trip to read the registry each attempt.
          To create a DSN-less connection with a Server.MapPath expression:
          1.   Upload the database file to the remote server.
               Make a note of its virtual path—for example, /jsmith/data/statistics.mdb.
          2.   Open one of your site’s pages in UltraDev and choose Modify > Connections.

               The Connections dialog box appears.


                                           LOVELY PROFESSIONAL UNIVERSITY                                   297
   298   299   300   301   302   303   304   305   306   307   308