Results 1 to 3 of 3

Thread: Database

  1. #1
    Join Date
    Dec 1969

    Default Database

    I have been coding ASP for quite some time now, and what I have been doing, is only opening a database at the time that I need it, reading/writing data, and then closing the database. This gets quite tedious if the site that is under development is fairly database dependant, and the one that I am about to embark on is EXTREMELY database dependant, ie - Every page will need access to the database.<BR> I have been thinking about how I can reduce the amount of code that I would need (Or copy paste :-) ) and thought of using a cookie so store the Connection. I know this would work - but is it safe to do this? The one worry I have, is that the users of this database may not come out of the site, by clicking on the close button that I will probably have to put in myself, that actually closes the database connection.<BR> Does anyone else have any good tips on the best way of keeping a connection to a database, without expresly opening and closing it in each any every file?

  2. #2
    Joel N Guest

    Default RE: Database

    Put your db logic in a componenet and register that component in MTS/COM+.<BR><BR>I&#039;m a bit confused by your statment that you can store the connection in a cookie. You could store a connection string in a client-side cookie, or store a connection object in a Session variable (bad idea), but it sounds like you&#039;re saying you could store a connection object in a client side cookie and that just isn&#039;t possible. If the site you&#039;re building will really be database intensive then if you want any degree of scalability you need to use middle-tier components for db access and use MTS/COM+ for connection management.

  3. #3
    Join Date
    Dec 1969

    Default RE: Database

    why not put ure connection string in a file called db.asp containing following code for instance:<BR><BR>********************************* *****<BR>&#039;this procedure is called wherever a connection is needed. Returns &#039;sagedbc&#039; as active connection<BR>sub openConn()<BR>&#039;use appropriate connection string<BR><BR>sagestrConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.MapPath("admin/stock.mdb")<BR>Set sagedbc = Server.CreateObject("ADODB.Connection")<BR>sagedbc .open sagestrConn<BR>end sub<BR><BR><BR>sub closeConn()<BR><BR> if isobject(sagedbc) then<BR> if sagedbc.State = adStateOpen then<BR> sagedbc.Close<BR> end if<BR> set sagedbc = nothing<BR> end if<BR><BR><BR>end sub<BR>**************************8<BR>then on pages requiring a connection - add db.asp as an include file and call openConn and closeConn whenever needed :-)<BR><BR>easi peesy lemon squeezy<BR><BR>GaryDee<BR>Ireland

Posting Permissions

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