ADODB.Connection error - asp.net

I am trying to learn asp.net, and have hit a problem early on.
I am attempting to connect to a database that I have create on Net Registry's Cloud Hosting.
I just receive a 500 error when i try to access the page.
(I am on a Mac as well if this matters at all.)
Here is my code:
<% # Language="VBScript" %>
<head>
<title>Form to database</title>
</head>
<body>
<%
Dim page: page = Request.ServerVariables("SCRIPT_NAME")
If Request.Form <> "" Then
Dim name: name= Request.Form("name")
Dim email: email = Request.Form("email")
Dim comments: comments = Request.Form("comments")
Dim sql: sql = "INSERT INTO users_tbl " & _
"([name], email, comments) " & _
"VALUES ('" & name & "','" & email & "','" & comments & "')"
Dim conn: Set conn = Server.CreateObject("ADODB.Connection")
Dim str: str = "SERVER=MYSQL-5.idealinsurance.com.au;
DATABASE=ideal_idealinsurance_com_au; UID=XXXXXXXXXX;PASSWORD=XXXXXXXX; OPTION=3"
conn.Open(str)
conn.Execute(sql)
conn.Close
Set conn = Nothing
Dim message: message = "The form information was inserted successfully."
End If
%>
<form action="<%=page%>" method="post">
name:<input name="name"><br>
email:<input name="email"><br>
comments: <textarea name="comments"></textarea><br>
<input name="submit" type="submit" value="Submit">
</form>
<p>
<%=message%>
</body>
</html>

Related

Need Replacement for MS Index Service on Server 2012 with Classic ASP (VB)

I have just migrated a website from Server 2003 to Server 2012, and MS Indexing service is not available.
In doing some research, I found that MS Search Service is the 'replacement,' and, as such, I installed it on Server 2012. Beyond this, I haven't found what ASP-Classic (VB) code would be necessary to enable the new Search Service to catalog my documents, as Indexing Service did.
Does MS Search Service have the capability and flexibility to catalog and search documents, and return results in the same way that MS Indexing Service did?
Below is an example of the code that currently calls the MS Indexing Service (on the Windows 2003 server):
<%
Dim strQuery ' The text of our query
Dim objQuery ' The index server query object
Dim rstResults ' A recordset of results returned from I.S.
Dim objField ' Field object for loop
Dim objUtility
' Retreive the query from the querystring
strQuery = Request.QueryString("CiRestriction")
if strQuery <> "" then
if Request.QueryString("ExactPhrase") = "Yes" then
strQuery = """" & strQuery & """"
end if
end if
' If the query isn't blank them proceed
If strQuery <> "" Then
' Create our index server object
Set objQuery = Server.CreateObject("IXSSO.Query")
' Set its properties
objQuery.Catalog = "Test_Docs" ' Catalog to query
objQuery.MaxRecords = 75 ' Max # of records to return
objQuery.SortBy = "Rank[d], size"
objQuery.Columns = "Characterization, DocTitle, Directory, Filename, Path, Rank, Size, Vpath, Write"
' Build our Query: Hide admin page and FPSE pages
'strQuery = "(" & strQuery & ")" _
' & " AND NOT #filename = *admin*" _
' & " AND NOT #path *\_vti_*"
' Uncomment to only look for files modified last 5 days
'strQuery = strQuery & " AND #write > -5d"
' To set more complex scopes we use the utility object.
' You can call AddScopeToQuery as many times as you need to.
' Shallow includes just files in that folder. Deep includes
' subfolders as well.
'
Set objUtility = Server.CreateObject("IXSSO.Util")
objUtility.AddScopeToQuery objQuery, "d:\test_shares\test_docs", "deep"
objQuery.Query = strQuery ' Query text
Set rstResults = objQuery.CreateRecordset("nonsequential") ' Get a recordset of our results back from Index Server
' Check for no records
If rstResults.EOF Then
Response.Write "Sorry. No results found."
Else
' Print out # of results
Response.Write "<p><strong>"
Response.Write rstResults.RecordCount
Response.Write "</strong> results found:</p>"
' Loop through results
Do While Not rstResults.EOF
' Loop through Fields
' Pretty is as pretty does... good enough:
%>
<%KSize=formatnumber(rstResults.Fields("size"))
KSize= round(KSize/1024,0)%>
<p>
<%'test below using PoorMansIsNull function%>
<% If PoorMansIsNull(rstResults.Fields("DocTitle")) Or rstResults.Fields("DocTitle")="" Then %>
<%= PathToVpath(rstResults.Fields("filename")) %>
<% Else %>
<font size="3"><%= rstResults.Fields("DocTitle") %></font>
<% End If %>
<br><%= rstResults.Fields("Characterization") %><br>
<font color="#009900"><%= PathToVpath(rstResults.Fields("path")) %> - <%= KSize %>k<br /></font>
</p>
<%
' Move to next result
rstResults.MoveNext
Loop
rstResults.MoveFirst
Response.Write "<pre>"
'Response.Write rstResults.GetString()
Response.Write "</pre>"
End If
' Kill our recordset object
Set rstResults = Nothing
Set objUtility = Nothing
Set objQuery = Nothing
End If
%>
</body>
</html>
<%
Function PathToVpath(strPath)
Const strWebRoot = "d:\test_shares\test_docs\"
Dim strTemp
strTemp = strPath
strTemp = Replace(strTemp, strWebRoot, "\")
strTemp = Replace(strTemp, "\", "/")
PathToVpath = strTemp
End Function
%>
And, the results would be listed, per document (the name of the document, with excerpt from document text, along with title, size), as illustrated below:
Thanks for any leads and/or alternatives.
This example is in fact incorrect. It does not work. The following code:
objRecordSet.Open "SELECT Top 20 " & _
"System.ItemPathDisplay " & _
",System.ItemName " & _
",System.Size " & _
"FROM SYSTEMINDEX", objConnection & _
"WHERE SCOPE='file:E:\MANIF\DAAP\AC'"
Should really use the connection object at the end of the query. Spent a few hours wondering why the WHERE clause was not working.
objRecordSet.Open "SELECT Top 20 " & _
"System.ItemPathDisplay " & _
",System.ItemName " & _
",System.Size " & _
"FROM SYSTEMINDEX " & _
"WHERE SCOPE='file:E:\MANIF\DAAP\AC'", objConnection
This should help all who are having the same difficulty.
I'm facing the same problem. I've found a MS guide about this issue: Querying the Index with Windows Search SQL Syntax.
I've tested this ASP (Classic) code and ran ok:
<html>
<body>
Results<br>
<ol>
<%
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
objConnection.Open "Provider=Search.CollatorDSO;Extended Properties='Application=Windows';"
'change directory on scope clause
objRecordSet.Open "SELECT Top 20 " & _
"System.ItemPathDisplay " & _
",System.ItemName " & _
",System.Size " & _
"FROM SYSTEMINDEX" & _
" WHERE SCOPE='file:E:\MANIF\DAAP\AC'", objConnection
objRecordSet.MoveFirst
Do Until (objRecordSet.EOF)
%>
<li>
<strong>Path Display:</strong><%=objRecordSet("System.ItemPathDisplay")%><br>
<strong>Name:</strong><%=objRecordSet("System.ItemName")%><br>
<strong>Size:</strong><%=objRecordSet("System.Size")%><br>
<hr>
</li>
<%
objRecordSet.MoveNext
Loop
objRecordSet.Close
Set objRecordSet = Nothing
objConnection.Close
Set objConnection = Nothing
%>
</ol>
</body>
</html>
Other alternatives:
Try to register asp dll in windows server. For I could see, nobody related success on this approch. See this post;
Create a VM a previous windows version to support your asp. See this MS article.
Hope it could help you.

ASP and LDAP: The connection cannot be used to perform this operation. It is either closed or invalid in this context.

Continuing with ASP, I have sine code which gives the user a form, which displays data currently held in Active Directory, and lets the user update some of their details. I have tried everything but am stil getting the error
"ADODB.Command error '800a0e7d'
The connection cannot be used to perform this operation. It is either closed or invalid in this context.
/editentry.asp, line 31"
Anyway, my code isL
<%# Language=VBScript %>
<% response.Buffer = True
'Define the AD OU that contains our users
dim ADUser, user, firstname, lastname, email, telephonenumber, mobile
'This initializes all of our variables
user = request.querystring("account_name")
'This puts the value of the account_name into a variable
if len(user) = 0 then
'If the length of the username is equal to 0
response.write "Please supply a username in the query string"
elseif len(user) > 0 then
'Else is length of user is greater than 0
ADUser = "LDAP://OU=Staff,OU=Users,DC=Something,DC=internal"
' Make AD connection and run query
Set objCon = Server.CreateObject("ADODB.Connection")
objCon.provider ="ADsDSOObject"
objCon.Properties("User ID") = "EXAMPLE\Testuser"
objCon.Properties("Password") = "TestUser1!"
objCon.Properties("Encrypt Password") = TRUE
objCon.open "Active Directory Provider"
Set objCom = CreateObject("ADODB.Command")
objCom.CommandText ="select ADsPath, givenName,sn,mail,telephonenumber,mobile,sAMAccountName FROM '"+ ADUser +"' where sAMAccountname='"& user & "'"
'objCom.Properties("searchscope") = ADS_SCOPE_ONELEVEL
Set objRS = objCom.Execute
' Loop over returned recordset and output HTML
Response.Write vbCrLf
Do While Not objRS.EOF Or objRS.BOF
Response.Write " <form action='editentry.asp?account_name=" + user + "' method='POST'>"
Response.Write "<p><label for='firstname'>Firstname</label><input type='text' id='firstname' value='" + objRS("givenName") +"' name='fname'></p>"
Response.Write "<p><label for='lastname'>Lastname</label><input type='text' id='lastname' value='" + objRS("sn") +"' name='lname'></p>"
Response.Write "<p><label for='mail'>E-Mail Address</label><input type='text' id='lastname' value='" + objRS("mail") +"' name='email'></p>"
Response.Write "<p><label for='mobile'>Mobile</label><input type='text' id='mobile' value='" + objRS("mobile") +"' name='mobile'></p>"
Response.Write "<p><label for='telephone'>Telephone Number</label><input type='text' id='email' value='" + objRS("telephonenumber") +"' name='telephonenumber'></p>"
Response.Write "<p><input type='hidden' id='subval' value='1' name='subval'></p>"
Response.Write "<p><input type='submit' name='submit'><input type='reset' name='reset'></p>"
Response.Write "</form>" + vbCrLf
objRS.MoveNext
Response.Flush
Loop
if isEmpty(request.form("subval"))=FALSE then
'Subval will contain 1 if the form is submitted, else it won't exist, so we can check the form has been submitted by reading it back
firstname = request.form("fname")
lastname = request.form("lname")
email = request.form("email")
mobile = request.form("mobile")
telephonenumber = request.form("telephonenumber")
Do While Not objRS.EOF
Set usr = GetObject(objRS.Fields("ADsPath").Value)
usr.Put "gjvenName", firstname
usr.Put "sn", lastname
usr.Put "mail", email
usr.Put "mobile", mobile
usr.Put "telephonenumber", telephonenumber
usr.SetInfo
objRS.MoveNext
loop
response.write "Entry has been updated "
end if
end if
' Clean up
objRS.Close
objCon.Close
Set objRS = Nothing
Set objCon = Nothing
Set objCom = Nothing
%>
I'm not sure what is wrong here
Assign the connection of the command object (before calling the Execute function) like this:
Set objCom.ActiveConnection = objCon

need to implement recaptcha in .asp page

anyone please know how to add recaptcha in .asp , i am having public and privte keys
<TD align="middle">Security Code: </TD>
<TD align="middle">
<script type="text/javascript"
src="http://www.google.com/recaptcha/api/challenge?k=01M2eMS32Xs6oGtCaBu3AkHQ==">
</script>
<noscript>
<iframe src="http://www.google.com/recaptcha/api/noscript?k=01M2eMS32Xs6oGtCaBu3AkHQ=="
height="300" width="500" frameborder="0"></iframe><br>
<textarea name="recaptcha_challenge_field" rows="3" cols="40">
</textarea>
<input type="hidden" name="recaptcha_response_field"
value="manual_challenge">
</noscript>
</TD>
Using reCAPTCHA with Classic ASP
The reCAPTCHA ASP guide provides a simple way to place a CAPTCHA on your ASP page, helping you stop bots from abusing it. The code below wraps the reCAPTCHA API.
After you've signed up for your API keys, you can add reCAPTCHA to your classic ASP site by pasting the code below at the top of your ASP page:
<%
recaptcha_challenge_field = Request("recaptcha_challenge_field")
recaptcha_response_field = Request("recaptcha_response_field")
recaptcha_public_key = "your_public_key" ' your public key
recaptcha_private_key = "your_private_key" ' your private key
' returns the HTML for the widget
function recaptcha_challenge_writer()
recaptcha_challenge_writer = _
"<script type=""text/javascript"">" & _
"var RecaptchaOptions = {" & _
" theme : 'red'," & _
" tabindex : 0" & _
"};" & _
"</script>" & _
"<script type=""text/javascript"" src=""http://www.google.com/recaptcha/api/challenge?k=" & recaptcha_public_key & """></script>" & _
"<noscript>" & _
"<iframe src=""http://www.google.com/recaptcha/api/noscript?k=" & recaptcha_public_key & """ frameborder=""1""></iframe><>" & _
"<textarea name=""recaptcha_challenge_field"" rows=""3"" cols=""40""></textarea>" & _
"<input type=""hidden"" name=""recaptcha_response_field""value=""manual_challenge"">" & _
"</noscript>"
end function
' returns "" if correct, otherwise it returns the error response
function recaptcha_confirm(rechallenge,reresponse)
Dim VarString
VarString = _
"privatekey=" & recaptcha_private_key & _
"&remoteip=" & Request.ServerVariables("REMOTE_ADDR") & _
"&challenge=" & rechallenge & _
"&response=" & reresponse
Dim objXmlHttp
Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
objXmlHttp.open "POST", "http://www.google.com/recaptcha/api/verify", False
objXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
objXmlHttp.send VarString
Dim ResponseString
ResponseString = split(objXmlHttp.responseText, vblf)
Set objXmlHttp = Nothing
if ResponseString(0) = "true" then
'They answered correctly
recaptcha_confirm = ""
else
'They answered incorrectly
recaptcha_confirm = ResponseString(1)
end if
end function
server_response = ""
newCaptcha = True
if (recaptcha_challenge_field <> "" or recaptcha_response_field <> "") then
server_response = recaptcha_confirm(recaptcha_challenge_field, recaptcha_response_field)
newCaptcha = False
end if
%>
What happens here is the variables server_response and newCaptcha are set whenever the page is loaded, allowing you to determine the state of your page.
You can use the following HTML as a skeleton:
<html>
<body>
<% if server_response <> "" or newCaptcha then %>
<% if newCaptcha = False then %>
<!-- An error occurred -->
Wrong!
<% end if %>
<!-- Generating the form -->
<form action="recaptcha.asp" method="post">
<%=recaptcha_challenge_writer()%>
</form>
<% else %>
<!-- The solution was correct -->
Correct!
<%end if%>
</body>
</html>
As shown here:
http://developers.google.com/recaptcha/docs/asp

ASP Classsic - Insert into Excel .XLS columns or Create a Real Excel Format File

I would like to add my MS SQL data into the Excel .XLS file below.
I tried the following:
<%
Response.Clear
Response.Buffer = False
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment;filename=example.xls"
' --OPEN MS SQL DATABASE CODE--
' --OPEN RECORDSET CODE--
%>
<table>
<tr>
<th>DEBNAME</th>
<th>INV_ID</th>
<th>INV_DATE</th>
<th>PO_NO</th>
<th>INVAMT</th>
</tr>
<% 'START OF: ROW LOOP
Do Until objRS.EOF
%>
<tr>
<td><%=objRS("DEBNAME")%></td>
<td><%=objRS("INV_ID")%></td>
<td><%=objRS("INV_DATE")%></td>
<td><%=objRS("PO_NO")%></td>
<td><%=objRS("INVAMT")%></td>
</tr>
<%
objRS.MoveNext
Loop
objRS.Close
'END OF: ROW LOOP
%>
</table>
THEN WHEN I TRY TO OPEN IT, IT GIVES ME THIS ERROR:
I think this is because the file only has HTML code inside it (I opened it via Notepad to check it out)
If I click on Yes the data will show but I would like to generate a real .xls file or use an empty.xls file, clone it, and then insert the data into it.
THANKS FOR ANY HELP!
This is how my empty.xls file looks
Using an empty file that ready to fill is the most painless method.
After filling the sheet(s) via related data providers, you can serve the static excel file or stream it.
Here's the demo : http://aspfiddle.com/ymuikl0id4/test.asp (will be deleted a few days later)
Make sure that you have permission to create new files.
Hope it helps.
<%#Language=VBScript CodePage=65001%>
<%
If Request.Form.Count Then 'form handling
Dim Fso
Set Fso = Server.CreateObject("Scripting.FileSystemObject")
Dim emptyXlsFileName
emptyXlsFileName = Server.Mappath("test.xls") 'empty original file path
Dim filledXlsFileName
filledXlsFileName = Replace(Fso.GetTempName, ".tmp", ".xls") 'temp file will be created and filled
Fso.CopyFile emptyXlsFileName, Server.Mappath(filledXlsFileName)
Dim Connection
Set Connection = Server.CreateObject("Adodb.Connection")
Connection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath(filledXlsFileName) & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=0"";"
'Since Jet.OLEDB.4.0 is a 32-Bit only provider
'if you need to run this application in a 64-bit environment
'you have to install 64-bit version of Access Database Engine (http://www.microsoft.com/en-us/download/details.aspx?id=13255) to the server
'then use the following connection string instead
'Connection.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Server.Mappath(filledXlsFileName) & ";Extended Properties=""Excel 8.0;HDR=YES;IMEX=0"";"
Dim Recordset
Set Recordset = Server.CreateObject("Adodb.Recordset")
Recordset.Open "[Sheet1$]", Connection, , 3
Recordset.Addnew
Recordset("DEBNAME").Value = Request.Form("DEBNAME")
Recordset("INV_ID").Value = Request.Form("INV_ID")
Recordset("INV_DATE").Value = Request.Form("INV_DATE")
Recordset("PO_NO").Value = Request.Form("PO_NO")
Recordset("INVAMT").Value = Request.Form("INVAMT")
Recordset.Update
Recordset.Close
Set Recordset = Nothing
Connection.Close
Set Connection = Nothing
Const BufferSize = 8192
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment;filename=example.xls"
Dim Stm
Set Stm = Server.CreateObject("Adodb.Stream")
Stm.Type = 1 'adTypeBinary
Stm.Open
Stm.LoadFromFile Server.Mappath(filledXlsFileName)
Do While Not Stm.EOS
Response.BinaryWrite Stm.Read(BufferSize)
Response.Flush
If Not Response.IsClientConnected Then Exit Do
Loop
Stm.Close
Set Stm = Nothing
Fso.DeleteFile Server.Mappath(filledXlsFileName)
Response.End
Set Fso = Nothing
End If
%><!doctype html>
<html lang="en">
<head>
<title>Insert Into Excel File</title>
<meta charset="utf-8">
</head>
<body>
<form method="post" target="_blank">
<table>
<tr><td>DEBNAME</td><td><input type="text" name="DEBNAME" value="John Doe" /></td></tr>
<tr><td>INV_ID</td><td><input type="text" name="INV_ID" value="123" /></td></tr>
<tr><td>INV_DATE</td><td><input type="text" name="INV_DATE" value="24 Jun, 2014" /></td></tr>
<tr><td>PO_NO</td><td><input type="text" name="PO_NO" value="321" /></td></tr>
<tr><td>INVAMT</td><td><input type="text" name="INVAMT" value="etc" /></td></tr>
<tr><td> </td><td><input type="submit" value="Add & Download" /></td></tr>
</table>
</form>
</body>
</html>
This will only be a partial/hack answer, because for everything from Excel 2007 on, I don't know that you can bypass that warning (unless you use a third-party library, and I don't know of any for ASP classic -- plenty of choices for ASP.NET). Here is a MS article on this subject, and it leads to the hack:
http://blogs.msdn.com/b/vsofficedeveloper/archive/2008/03/11/excel-2007-extension-warning.aspx
What you can do is alter your code slightly and deliver the data in CSV format. This will still download and open directly in Excel, but you won't get the warning. So here's the guts of it:
<%
Response.Clear
Response.Buffer = False
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment;filename=example.csv"
Response.Write "DEBNAME, INV_ID, INV_DATE, PO_NO, INVAMT" & vbCRLF
Do Until objRS.EOF
Response.Write objRS("DEBNAME") & ", " & objRS("INV_ID") & ", " & objRS("INV_DATE") & ", " & objRS("PO_NO") & ", " & objRS("INVAMT") & vbCRLF
objRS.MoveNext
Loop
objRS.Close
%>

how to display photo from active directory in classic asp

how to display photo from active directory in classic asp?
I can log on to our AD and query user name telephone ect from a calssic asp page. the thumbnail photo field just returns a string, how do I format that to diaplay photo in classic asp please?
If I understand your question correctly, you would get the image file in binary using FileSystemObject and use response.contenttype = "image/jpeg" when you return the data of the image so it renders the content as an image.
You can also render the photo inline in an image:
...img src=[base64 presentation of the image]>...
HTML image tag with base64 string (data URI)
You can do it by using html img tag. for example:
<img src="<%=myPhotoUrl%>">
In asp code block, you must declare it as:
<%
Response.Write "<img src=""" & myPhotoUrl & """>"
%>
So the answer I have come up with that works is:
strUsername = request.querystring("req")
strUserRole = request.querystring("rol")
Set objDomain = GetObject ("GC://rootDSE")
objADsPath = objDomain.Get("defaultNamingContext")
Set objDomain = Nothing
Set con = Server.CreateObject("ADODB.Connection")
con.provider ="ADsDSOObject"
con.Properties("User ID") = "XXXXXXXXXXX"
con.Properties("Password") = "XXXXXXXXXXXXXXX"
con.Properties("Encrypt Password") = False
con.open "Active Directory Provider"
Set Com = CreateObject("ADODB.Command")
Set Com.ActiveConnection = con
Com.CommandText ="select name,telephonenumber,mail,thumbnailPhoto, Department, title FROM 'GC://"+objADsPath+"' where sAMAccountname='"+strUsername+"'"
Set rs = Com.Execute
if not rs.eof then
tmpphoto=rs("thumbnailPhoto")
tmpdept=rs("Department")
tmptitle=rs("title")
name=rs("name")
telephonenumber=rs("telephonenumber")
mail=rs("mail")
NameArr = Split(name, " ")
cname = NameArr(0)
sname = NameArr(1)
rs.Close
con.Close
Set rs = Nothing
Set con = Nothing
%>
<div id="card"><img src="badge.jpg" width="100%"/>
<div id="personname"><%=cname & " " & sname%></div>
<div id="persongroup"><%=tmptitle%></div>
<div id="persondept"><%=tmpdept%></div>
<div id="personrole"><%=strUserRole%></div>
<div id="personimage">
<img src="getaduserimage.asp?req=NAME.SURNAME" width="100" height="100" frameborder="0" scrolling="no" />
</div>
<div id="logoimage"><img src="OUR_logo_white_small.png" width="100"/></div>
<%
else
cname = strUsername & " Not found"
end if
%>
<% 'getaduserimage.asp file contains:
strUsername = request.querystring("req")
Set objDomain = GetObject ("GC://rootDSE")
objADsPath = objDomain.Get("defaultNamingContext")
Set objDomain = Nothing
Set con = Server.CreateObject("ADODB.Connection")
con.provider ="ADsDSOObject"
con.Properties("User ID") = "xxxxxx"
con.Properties("Password") = "xxxxxxxx"
con.Properties("Encrypt Password") = False
con.open "Active Directory Provider"
Set Com = CreateObject("ADODB.Command")
Set Com.ActiveConnection = con
Com.CommandText ="select thumbnailPhoto FROM 'GC://"+objADsPath+"' where sAMAccountname='"+strUsername+"'"
Set rs = Com.Execute
Response.Expires = 0
Response.Buffer = TRUE
Response.Clear
Response.ContentType = "image/jpeg"
'#### Assuming your images are jpegs
if not rs.eof then
Response.BinaryWrite rs("thumbnailPhoto")
else
response.write "image for " & strUsername & " Not found"
end if
rs.Close
con.Close
Set rs = Nothing
Set con = Nothing
%>

Resources