Last week we learned how to make really, really dynamic websites. That's great and all, but how to you make sure your really, really dynamic website will stand the test of time? With DB Include Files, that's how!
It's quite simple really. First, in every one of your pages, include a file like this (from an Anonymous reader) at the top, before any of your code ...
' dbheader.inc (C) 2002 Initech Solutions [ED: name obviously changed] Dim aryConnections(8) Set aryConnections(0) = Server.CreateObject("ADODB.Connection") Set aryConnections(1) = Server.CreateObject("ADODB.Connection") Set aryConnections(2) = Server.CreateObject("ADODB.Connection") Set aryConnections(3) = Server.CreateObject("ADODB.Connection") Set aryConnections(4) = Server.CreateObject("ADODB.Connection") Set aryConnections(5) = Server.CreateObject("ADODB.Connection") Set aryConnections(6) = Server.CreateObject("ADODB.Connection") Set aryConnections(7) = Server.CreateObject("ADODB.Connection")
aryConnections(0).Open "Driver={SQL Server};Server=SQL2KDBSRV;Database=WWW_SITE;Uid=sa;Pwd=" aryConnections(1).Open "Driver={SQL Server};Server=SQL2KDBSRV;Database=WWW_SITE;Uid=sa;Pwd=" aryConnections(2).Open "Driver={SQL Server};Server=SQL2KDBSRV;Database=WWW_SITE;Uid=sa;Pwd=" aryConnections(3).Open "Driver={SQL Server};Server=SQL2KDBSRV;Database=WWW_SITE;Uid=sa;Pwd=" aryConnections(4).Open "Driver={SQL Server};Server=SQL2KDBSRV;Database=WWW_SITE;Uid=sa;Pwd=" aryConnections(5).Open "Driver={SQL Server};Server=SQL2KDBSRV;Database=MARKETING;Uid=sa;Pwd=" aryConnections(6).Open "Driver={SQL Server};Server=SQL2KDBSRV;Database=PRODUCTS;Uid=sa;Pwd=" aryConnections(7).Open "Driver={SQL Server};Server=SQL2KDBSRV;Database=WWW_SITE;Uid=sa;Pwd="
Dim aryRecordSets(8) Set aryRecordSets(0) = Server.CreateObject("ADODB.RecordSet") Set aryRecordSets(1) = Server.CreateObject("ADODB.RecordSet") Set aryRecordSets(2) = Server.CreateObject("ADODB.RecordSet") Set aryRecordSets(3) = Server.CreateObject("ADODB.RecordSet") Set aryRecordSets(4) = Server.CreateObject("ADODB.RecordSet") Set aryRecordSets(5) = Server.CreateObject("ADODB.RecordSet") Set aryRecordSets(6) = Server.CreateObject("ADODB.RecordSet") Set aryRecordSets(7) = Server.CreateObject("ADODB.RecordSet")
Make sense? If you think about it, most web pages will never use more than a single database connection. A few will use two, and every once in a while, you'll need three. But, by putting in eight, you're certain that you'll be set for the future. And if you ever need connections to other databases, just use higher numbers, since those won't get used anyway.
Of course, what header would be complete without a footer? Put this at the bottom of every page ...
'dbheader.inc (C) 2002 Initech Solutions On Error Resume Next objConn.Close
Great! Now just sit back and wait for your website to scale!