0

In classic asp I have the file open.asp and close.asp included at top and bottom of every page. Somewhere I have response.end in my codes. Do I need to close connection before response.end or the server translates the page to the end of page after response.end?

Content of open.asp:

Set objcon = Server.CreateObject("ADODB.Connection")
objcon.connectionString="DSN=something"
objcon.Open

content of close.asp:

objcon.close
set objcon=nothing

Please note that I have no problem with multiple connections and memory leak. My exact question is about behavior of of server against "Response.End"

Ali Sheikhpour
  • 10,475
  • 5
  • 41
  • 82
  • Yes. You do. otherwise you might end up with a memory leak. – Zohar Peled May 07 '17 at 11:02
  • 1
    Well, before calling the Response.End you can call Server.Execute("close.asp") – Shadow The GPT Wizard May 08 '17 at 06:54
  • Possible duplicate of [Connection leaks in Classic ASP using Server.CreateObject("ADODB.Connection")](http://stackoverflow.com/questions/7896241/connection-leaks-in-classic-asp-using-server-createobjectadodb-connection) – user692942 May 08 '17 at 08:17
  • Another possible duplicate of [Properly closing a database connection - VBScript + MS SQL](//stackoverflow.com/q/12536414) – user692942 May 08 '17 at 08:18
  • 1
    Possible duplicate of [Properly closing a database connection - VBScript + MS SQL](http://stackoverflow.com/questions/12536414/properly-closing-a-database-connection-vbscript-ms-sql) – Paul Roub May 08 '17 at 13:25

1 Answers1

0

Response.End stops further execution of the page. From the docs: "The remaining contents of the file are not processed." So, no, the connection object won't get cleaned up in this scenario.

It's better to go ahead and create connection objects at a more granular level and destroy/release them as soon as possible back to the ADO connection pool, which is what manages the actual connections to the database. Reusing a connection object leaves it more vulnerable to not getting cleaned up properly.

Kevin Collins
  • 1,453
  • 1
  • 10
  • 16