I've run into a problem with my VPS server at hostmysite. It seems my server
gets really low on memory due to database connections that are left open (so
I'm told by HMS) and HMS recommended this:
 
------------------------------------------
>From HMS support:
SQL memory problems like this usually happen because of looping queries, or
hanging connections. The best solution is to update your code, adjusting the
queries to close the connection to the database once complete. This will
ensure that the memory used for the query is then freed.

-------------------------------------------

OK so when I used to do ASP and VBScript I always closed and destroyed the
database connections and objects. However, I didn't even know there was a
way to do it with queries in CF. Is this right? Should I somehow be closing
database connections? In most cases, these are just <cfquery> tags used with
either <cfloop> or <cfoutput> to display the query results. However, there
is one area of this site where I used Java inside of <cfscript> to open a
database connection so I am guessing that may be where I should be closing
the connection. The code reminds of the way I used to do it with ASP. See
example:

<cfscript>
  classLoader = createObject("java", "java.lang.Class");
  classLoader.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  dm = createObject("java","java.sql.DriverManager");  
  con = dm.getConnection("jdbc:odbc:DRIVER={SQL Server};Database=" &
application.db_name & ";Server=" & application.dbserver_name & ";",
application.db_user, application.db_pword);  
  qText = "Select * FROM SomeTable";
  st = con.createStatement();
  rs = st.ExecuteQuery(qText);
  q = createObject("java", "coldfusion.sql.QueryTable").init(rs);
</cfscript>

1. Ok so I am guessing there is a way to close the connection and destory
the objects. If so, could someone send me a snippet of code to do that? 

2. I'm not sure if closing a database connection is needed when using
<cfquery> tags. If so, I've been missing that part for well over 5 years of
cf coding. Ooops!!! Hope that is not the case.

 

-Dusty

 



-------------------------------------------------------------
Annual Sponsor FigLeaf Software - http://www.figleaf.com

To unsubscribe from this list, manage your profile @ 
http://www.acfug.org?fa=login.edituserform

For more info, see http://www.acfug.org/mailinglists
Archive @ http://www.mail-archive.com/discussion%40acfug.org/
List hosted by http://www.fusionlink.com
-------------------------------------------------------------

Reply via email to