First tip is the best way to get data from SQL Server. Most people use ADO Recordset and loop through it. This means you have a connection to the SQL Server open while executing the script. A much better way is to use the GetRows() function in ADO:
Dim db, dbrs, sql, ConnString, users, user
ConnString = "DSN=YourDSN;"
sql = "SELECT UserId, Username FROM Users ORDER BY Username;"
' GET DATA
set db = server.createobject("ADODB.Connection")
set dbrs = server.createObject("ADODB.Recordset")
dbrs.open sql, db
if NOT dbrs.eof then
users = dbrs.GetRows()
set db = nothing
' DISPLAY DATA
for user = lbound(users,2) to ubound(users,2)
response.write "UserId: " & users(0,user)
response.write "Username: " & users(1,user)
Use the GetRows method to copy records from a Recordset into a two-dimensional array. The first subscript identifies the field and the second identifies the record number. The array variable is automatically dimensioned to the correct size when the GetRows method returns the data.
Const UserId = 0