ASP Tips and Tricks

A few things you might find useful...

DSN-Less Connections Are Faster

You can use DSN-less connections on our servers.
DSN-less connections are faster than System DSN connections because DSN-less avoids the server doing a registry lookup. Furthermore you can receive additional performance benefits by directly using the OLEDB layer.

Here is an example:

Dim Cn, dbPath 
dbPath = "F:\Domains\yourdomain.com\db\YourDb.mdb"
Set Cn = Server.CreateObject("ADODB.Connection")
'Using OLEDB (fastest but some SQL features may be unavailable)
Cn.Open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & dbPath
'Using the MS Access driver (faster than a DSN)
Cn.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & dbPath

Always Explicity Destroy Object Instances

If you have a recordset object called objRS make sure you always call:

objRS.Close 
Set objRS = Nothing

at the end of your script.

Speed Of The Response Object

<%=Now()%>

will execute faster than....

<%Response.write(Now())%>

Be Careful Using "On Error Resume Next"

If you have a loop on your code and you use "On Error Resume Next" (i.e. ignore any errors and keep running the script) and you generate an error in that code loop (be it a WHILE, DO, FOR), you could possibly create an infinite loop in your script.

It won't respond, and it could very well bring down your website with it... so be careful using it.

Declare Your Variables

Dim yourvariable

Explicitly declaring variables is not necessary, but it may save you some time when you come to debug your scripts, especially if you've simply made a typo when using a variable somewhere!

Exahost.co.uk - Affordable Windows Hosting Solutions
Exahost.co.uk - Affordable Windows Hosting Solutions