Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Closing a database connection
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Andy Povey
Starting Member

7 Posts

Posted - 20 March 2005 :  13:14:35  Show Profile
I have had my website at www.zintek.net suspended by the hosting company Fasthosts.co.uk

the reason the techincal support company have given me is that people have accessed my website (which is MS Access database driven), and have pages left open connected to the database (1500 plus).

They say they should be able to reactive the site by Tuesday or Wednesday of this week, but have told me in the meantime that I must add some code to my ASP pages that automatcially close the database/ recordsets.

can soem kind person please tell me what code I need to add to my ASP pages, and where about's in the code must it go?


many thanks

Andy

Edited by - Andy Povey on 20 March 2005 14:06:14

D3mon
Senior Member

United Kingdom
1685 Posts

Posted - 20 March 2005 :  13:17:04  Show Profile  Visit D3mon's Homepage
can you post an example page of your DB connection code? Would make it easier to suggest the DB closing code.


Snitz 'Speedball' : Site Integration Mod : Friendly Registration Mod
"In war, the victorious strategist only seeks battle after the victory has been won"

Edited by - D3mon on 20 March 2005 13:17:23
Go to Top of Page

Andy Povey
Starting Member

7 Posts

Posted - 20 March 2005 :  13:39:19  Show Profile
Not sure if you require code from connection string or my homepage, so have pasted both.

THIS IS THE CODE FROM MY CONNECTION STRING

<%
' FileName="Connection_ado_conn_string.htm"
' Type="ADO"
' DesigntimeType="ADO"
' HTTP="false"
' Catalog=""
' Schema=""
Dim MM_conn_readingspeedway_STRING
MM_conn_readingspeedway_STRING = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Andy\My Documents\Dreamweaver\zintek\readingspeedway\data\racersytgbf.mdb"
%>

--
THIS IS THE CODE FROM THE HOMEPAGE OF MY WEBSITE

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="../Connections/conn_readingspeedway.asp" -->
<%
Dim rs_liveupdates__MMColParam
rs_liveupdates__MMColParam = "15"
If (Request.QueryString("ID") <> "") Then
rs_liveupdates__MMColParam = Request.QueryString("ID")
End If
%>
<%
Dim rs_liveupdates
Dim rs_liveupdates_numRows

Set rs_liveupdates = Server.CreateObject("ADODB.Recordset")
rs_liveupdates.ActiveConnection = MM_conn_readingspeedway_STRING
rs_liveupdates.Source = "SELECT Articles.Brief, Articles.Category, Icon.Icon, articles.title FROM Articles, Icon WHERE Category = " + Replace(rs_liveupdates__MMColParam, "'", "''") + " AND Articles.Icon = Icon.ID AND Live ORDER BY StartDate DESC"
rs_liveupdates.CursorType = 0
rs_liveupdates.CursorLocation = 2
rs_liveupdates.LockType = 1
rs_liveupdates.Open()

rs_liveupdates_numRows = 0
%>
<%
Dim rs_showevent
Dim rs_showevent_numRows

Set rs_showevent = Server.CreateObject("ADODB.Recordset")
rs_showevent.ActiveConnection = MM_conn_readingspeedway_STRING
rs_showevent.Source = "SELECT Articles.ID, Articles.Title, Articles.Brief, Articles.StartDate, Categories.Description, Icon.Icon FROM Articles, Categories, Icon WHERE Articles.Category = Categories.ID AND Articles.Icon = Icon.ID AND Live AND Category <> 2 AND Category <> 15 AND Category <> 32 AND Category <> 20 AND Category <>4 AND CATEGORY <>5 ORDER BY Sticky ASC, Articles.StartDate DESC, Articles.Art_order DESC"
rs_showevent.CursorType = 0
rs_showevent.CursorLocation = 2
rs_showevent.LockType = 1
rs_showevent.Open()

rs_showevent_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = 9
Repeat1__index = 0
rs_showevent_numRows = rs_showevent_numRows + Repeat1__numRows
%>
<%
Dim MM_paramName
%>
<%
' *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters

Dim MM_keepNone
Dim MM_keepURL
Dim MM_keepForm
Dim MM_keepBoth

Dim MM_removeList
Dim MM_item
Dim MM_nextItem

' create the list of parameters which should not be maintained
MM_removeList = "&index="
If (MM_paramName <> "") Then
MM_removeList = MM_removeList & "&" & MM_paramName & "="
End If

MM_keepURL=""
MM_keepForm=""
MM_keepBoth=""
MM_keepNone=""

' add the URL parameters to the MM_keepURL string
For Each MM_item In Request.QueryString
MM_nextItem = "&" & MM_item & "="
If (InStr(1,MM_removeList,MM_nextItem,1) = 0) Then
MM_keepURL = MM_keepURL & MM_nextItem & Server.URLencode(Request.QueryString(MM_item))
End If
Next

' add the Form variables to the MM_keepForm string
For Each MM_item In Request.Form
MM_nextItem = "&" & MM_item & "="
If (InStr(1,MM_removeList,MM_nextItem,1) = 0) Then
MM_keepForm = MM_keepForm & MM_nextItem & Server.URLencode(Request.Form(MM_item))
End If
Next

' create the Form + URL string and remove the intial '&' from each of the strings
MM_keepBoth = MM_keepURL & MM_keepForm
If (MM_keepBoth <> "") Then
MM_keepBoth = Right(MM_keepBoth, Len(MM_keepBoth) - 1)
End If
If (MM_keepURL <> "") Then
MM_keepURL = Right(MM_keepURL, Len(MM_keepURL) - 1)
End If
If (MM_keepForm <> "") Then
MM_keepForm = Right(MM_keepForm, Len(MM_keepForm) - 1)
End If

' a utility function used for adding additional parameters to these strings
Function MM_joinChar(firstItem)
If (firstItem <> "") Then
MM_joinChar = "&"
Else
MM_joinChar = ""
End If
End Function
%>
<SCRIPT runat=SERVER language=VBSCRIPT>
function DoDateTime(str, nNamedFormat, nLCID)
dim strRet
dim nOldLCID

strRet = str
If (nLCID > -1) Then
oldLCID = Session.LCID
End If

On Error Resume Next

If (nLCID > -1) Then
Session.LCID = nLCID
End If

If ((nLCID < 0) Or (Session.LCID = nLCID)) Then
strRet = FormatDateTime(str, nNamedFormat)
End If

If (nLCID > -1) Then
Session.LCID = oldLCID
End If

DoDateTime = strRet
End Function
</SCRIPT>
Go to Top of Page

Classicmotorcycling
Development Team Leader

Australia
2085 Posts

Posted - 20 March 2005 :  15:46:47  Show Profile
What you want at the bottom of your code is something like this:
<%
rs_showevent.Close
Set rs_showevent = Nothing
%>
That will close the SQL calls to the DB.

I hope it helps...

Cheers,

David Greening
Go to Top of Page

Andy Povey
Starting Member

7 Posts

Posted - 20 March 2005 :  15:54:59  Show Profile
quote:
Originally posted by Classicmotorcycling

What you want at the bottom of your code is something like this:
<%
rs_showevent.Close
Set rs_showevent = Nothing
%>
That will close the SQL calls to the DB.

I hope it helps...




Thanks very much - I will try that when my domain gets reactivated by the hosting company. I have to ring them when they re-open in the morning (I'm I the UK by the way).

Do I place that code just before the </head> ?

By the way, does the Snitz forum alraedy have this code placed in its pages?
Go to Top of Page

Classicmotorcycling
Development Team Leader

Australia
2085 Posts

Posted - 20 March 2005 :  16:18:19  Show Profile
Snitz already has it in it's code for their stuff. You need to place it as I said, at the bottom of your code just before the end function.

I hope that helps..

Cheers,

David Greening
Go to Top of Page

Andy Povey
Starting Member

7 Posts

Posted - 20 March 2005 :  16:30:34  Show Profile
quote:
Originally posted by Classicmotorcycling

Snitz already has it in it's code for their stuff. You need to place it as I said, at the bottom of your code just before the end function.

I hope that helps..



Is this correct at the bottom of my homepage/
<snip>

Internet</a></font> </span> </div>
</td>
<td width="5"> </td>
<td> </td>
</tr>
</table></td>
</tr>
</table>
</body>
<!-- InstanceEnd --></html>
<%
rs_liveupdates.Close
Set rs_liveupdates = Nothing
%>
<%
rs_showevent.Close
Set rs_showevent = Nothing
%>
Go to Top of Page

DarkDrift
Junior Member

USA
126 Posts

Posted - 20 March 2005 :  18:14:12  Show Profile  Visit DarkDrift's Homepage  Send DarkDrift an AOL message
yes why do you <% and %> every time a shorter way is to

<%
rs_liveupdates.Close
Set rs_liveupdates = Nothing

rs_showevent.Close
Set rs_showevent = Nothing
%>

just a tip

http://www.xcalliber.com - The Future of Boards
Go to Top of Page

Gremlin
General Help Moderator

New Zealand
7528 Posts

Posted - 24 March 2005 :  23:36:34  Show Profile  Visit Gremlin's Homepage
If your using Dreamweaver to create these pages it should normally always puts at the end of every page the required connection destroy/close commands.

Kiwihosting.Net - The Forum Hosting Specialists
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.29 seconds. Powered By: Snitz Forums 2000 Version 3.4.07