troubleshooting Question

How to Properly Open and Close Connection to SQL server database via ASP

Avatar of richardbe
richardbe asked on
Web Development
3 Comments1 Solution585 ViewsLast Modified:
I am having major problems with performance of my website using SQL server as the back-end db. Sometimes the website starts to time out and I have to call my ISP to restart it. The problems are due to the connection to the db not being cleaned up. The way I do it is connect to the db on each page using Set connObj = GetConnectionObj() and subsequently closing the connection at the end of the page CloseConnectionObj()

The functions are in the inc file below. What is wrong with this code?

I am using the code below to connect to the db:

Dim connObj       

Function GetConnectionObj

        Set connObj = Server.CreateObject("ADODB.Connection")
      connObj.Open "dsn=ay4441;Database=ay444;uid=ay444;pwd=test1"
        Set Application("connObj") = connObj

    Set GetConnectionObj = Application("connObj")

End Function

Sub CloseConnectionObj

    If (IsObject(Application("connObj")) = True) Then
        Dim connObj
        Set connObj = Application("connObj")
      Set Application("connObj") = Nothing
        Set connObj = Nothing
    End If

End Sub
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros