Need some knowledge about the connection

Results 1 to 6 of 6

Thread: Need some knowledge about the connection

  1. #1
    Goutam Guest

    Default Need some knowledge about the connection

    I have one confusion about database connection used in ASP pages. I think connection can be managed by two ways, one is using application variable in global.asa OR it can be done in each asp page. Which one is preferable? If I create the connection in each asp page do I need to close that connection explicitly in each page or is it taken care by asp (close the connection automatically when a new page is called)? Could anyone please make me clear about this? If you can suggest any site/article about this subject that will also be very helpful.<BR>Thanks & Regards<BR>Goutam

  2. #2
    Troy the ASP Boy Guest

    Default RE: Need some knowledge about the connection

    Global.Asa handles application and session variables. These are ongoing "connections" and different than the database connections. Database connections must be created each time you want to use them.<BR><BR>Databsse connections are usually closed automatically but you should always close them explicitly to free up server resources as quickly as possible.<BR><BR>Example:<BR>objRS.Close<BR>objCon n.Close<BR>set objRS = nothing<BR>set objConn = nothing<BR><BR>cheers<BR>troy the asp boy<BR>

  3. #3
    Goutam Guest

    Default RE: Need some knowledge about the connection

    Thanks for the prompt reply. I think the connection can be made in global.asa and later can be used in any page, I think it is something like this:<BR>in global.asa, set rs=Server.CreateObject("ADODB.Recordset")...<BR> dbname ="DSN=Mydbname"<BR>and later in any page, we can use <BR>,sqlstmt), where sqlstmt is the required sql in that page. Is it by any chance advantegious? <BR>Once again, thanks for the reply.

  4. #4
    troy the asp boy Guest

    Default RE: Need some knowledge about the connection

    what are you using for development (interdec/fp2k/homesite?)<BR><BR>all of my connections are made in the page that i am calling them from.<BR><BR>example:<BR>Set objConn = Server.CreateObject("ADODB.Connection")<BR>strConn ection = "DSN=mydb;Database=mydb;UID=sa;PWD=;"<BR>objConn.O pen strConnection<BR>Set objRS = Server.CreateObject("ADODB.Recordset")<BR><BR>is used every time (on each asp page) i want to connect to the database.<BR><BR>the global file holds application-level and session-level variables and objects.<BR><BR>cheers,<BR>troy<BR>

  5. #5
    xiaoming Guest

    Default RE: Need some knowledge about the connection

    hi, troy,<BR><BR>i think you can simply save the following code <BR>[Set objConn = Server.CreateObject("ADODB.Connection")<BR>strConn ection = "DSN=mydb;Database=mydb;UID=sa;PWD=;"]<BR>into a seperate "" file. <BR>and then you can call it on the top of each asp page by <BR>[&#060;!--#include file=""--&#062;]. <BR>i think it can save some of your typing work.<BR><BR>regards,<BR>xiaoming<BR><BR><BR>

  6. #6
    Join Date
    Dec 1969

    Default RE: Need some knowledge about the connection

    All of these will work with some additional code. And all are still opening the connection in each page. The connection would be closed by asp after the timeout period no matter what. It is good programming practice in my opinion to close the conenction as soon as you are done with it, to release the resources consumed by the connection. If you don&#039t you could have problems scaling your app.

Posting Permissions

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