View image from object ole db sql in classic asp - asp-classic

i am looking for a way to display in classic asp an image stored in an ole object of a sql db.
I've been looking around for a while, and the only thing I've found is such a thing that I've readjusted for my needs.
Unfortunately, however, it does not work, you only see a small square with a central x.
Do you have a suggestion?
Thanks
<%#LANGUAGE = VBScript%>
<%
id = Request.Querystring("id")
Set Conn1 = Server.CreateObject("ADODB.Connection")
Conn1.open "Driver={SQL Server};Server=ARCA;Database=CDB_EVEREX;Uid=everex;Pwd=everex1989;"
Dim strSQL, Rs
Set Rs = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM Attrezzatura_Catalogo WHERE ID_Catalogo=" & id & ";"
Rs.Open strSQL, Conn1, 3, 1
' Clear out the existing HTTP header information
'Response.Expires = 0
'Response.Buffer = TRUE
'Response.Clear
' Change the HTTP header to reflect that an image is being passed.
Response.ContentType = "image/bmp"
Response.BinaryWrite Rs("Immagine")
'Response.End
Rs.Close
Conn1.Close
Set Conn1 = Nothing
%>

make sure stored data is binary and try this?
<%
Response.ContentType = "image/bmp"
Response.Buffer = True
Response.AddHeader "Content-Disposition", "inline; filename=file001.bmp"
Response.Clear
Response.BinaryWrite Rs("Immagine")
Response.Flush
%>
maybe stored data can be base64. if data base64 then type directly into img src

Thanks for your answer, I tried your suggestion by adapting the code as you suggested (if I understand correctly) but the problem is not solved, you always see only the square with the central x :(
<%#LANGUAGE = VBScript%>
<%
id = Request.Querystring("id")
Set Conn1 = Server.CreateObject("ADODB.Connection")
Conn1.open "Driver={SQL Server};Server=ARCA;Database=CDB_EVEREX;Uid=everex;Pwd=everex1989;"
Dim strSQL, Rs
Set Rs = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM Attrezzatura_Catalogo WHERE ID_Catalogo=" & id & ";"
Rs.Open strSQL, Conn1, 3, 1
Response.ContentType = "image/bmp"
Response.Buffer = True
Response.AddHeader "Content-Disposition", "inline; filename=file001.bmp"
Response.Clear
Response.BinaryWrite Rs("Immagine")
Response.Flush
Rs.Close
Conn1.Close
Set Conn1 = Nothing
%>

Related

ASP Compare server variable with DB recordset

I'm new to this old scripting language but it's all we have right now. I'm trying to get this code work.
I would like to compare USERID servervariable with the same USERID from a recordset, then if true it will redirect the name of that USERID.
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=I:\storyData.mdb"
set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "SELECT USERIDFROM preprod", conn
strName = "John"
strNo = "This is not you"
If Request.ServerVariables("HTTP_USERID") = (rs.Fields.Item("USERID").Value) Then
Response.Redirect("story.html?" & "name=" & strName)
Else
Response.Redirect("story.html?" & "name=" & strNo)
End If
%>
I hope this makes any sense. It seems simple but can't get it to work.
thanks
what "doesn't" work?
looking at your code, it seems you're only checking the the first record of your query. I think you want to do something like this:
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=I:\storyData.mdb"
set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "SELECT count( USERID ) FROM preprod where userID = " & Request.ServerVariables("HTTP_USERID"), conn
strName = "John"
strNo = "This is not you"
if CInt( rs( 0 ) ) > 0 then
Response.Redirect("story.html?" & "name=" & strName)
Else
Response.Redirect("story.html?" & "name=" & strNo)
End If
%>
this code does a count of userIDs in your table and if there are more than 1, it'll do the redirect properly. A lot more efficient this way.

ASP stream send a TXT file created on the fly

I need to create and send a TXT file on the fly using classic asp. I know how to creates this file saving it into a directory and then send it using Server.CreateObject("ADODB.Stream") ... but what I wanted is to avoid saving it in the directory and just create and send on the fly.
In this case the TXT file is a list of records extracted from a MySql DB. One each line ...
strSQL = "SELECT * FROM mydb WHERE condition='ok';"
Set rs = my_conn.Execute(strSQL)
Response.Buffer = False
Dim objStream
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1 'adTypeBinary
objStream.Open
Response.ContentType = "application/x-unknown"
Response.Addheader "Content-Disposition", "attachment; filename=recordsfile.txt"
Response.BinaryWrite (dunno how to create a file with rs("field01") & " _ " & rs("field02") & vbnewline
objStream.Close
Set objStream = Nothing
Is it possible to do this ...meaning create a file in memory to strem/send ... orthere is no option but creating and saving it on disk before and send later ??
The following will work. Note: my example below assumes your recordset returns one field.
strSQL = "SELECT * FROM mydb WHERE condition='ok';"
Set rs = my_conn.Execute(strSQL)
if not rs.eof then
response.contentType = "application/octet-stream"
response.addHeader "Content-Disposition", "attachment; filename=recordsfile.txt"
do until rs.eof
response.write rs(0).value & vbcrlf
rs.movenext
loop
end if

How to a Hide Download Link

I created a protected area in my website, where only registered users can logon to download a restricted application (exe). But they can copy the download link and make it available on internet, so I am trying to find the simplest way to hide the download link (using ASP classic, if possible).
Here is what I got so far: http://forums.aspfree.com/code-bank-54/download-manager-downloading-files-secure-location-classic-asp-65239.html. But when using this download manager, the exe application unexplainably looses its digital signing :(
Please, can anyone give me some ideas? Maybe using PHP or Flash?
Thanks!
Here is the solution I found, using ASP classic:
<%
Option Explicit
Response.Buffer = True
If (not Session("Logged")) Then Response.End
Dim objFso
Dim objStream
Dim strFileName
Dim strFilePath
strFileName = "App.exe"
strFilePath = "d:\yoursitefolder\protectedfolder\"
Set objFso = Server.CreateObject("Scripting.FileSystemObject")
If objFso.FileExists(strFilePath & strFileName) Then
Response.AddHeader "Content-disposition", "filename=" & strFileName
Response.ContentType = "application/octet-stream"
Response.AddHeader "Pragma", "no-cache"
Response.AddHeader "Expires", "0"
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1
objStream.Open
objStream.LoadFromFile strFilePath & strFileName
Response.BinaryWrite(objStream.Read())
objStream.Close
Set objStream = Nothing
End If
Set objFso = Nothing
%>

Save ASP classic form into a specific column in excel

I'd to know if it's possible to have my asp classic form saved into a excel file in a column after submit?
Thank you all.
use the Microsoft.Jet.OLEDB Driver to access the excel sheet like so:
dim conn : set conn = server.createObject("ADODB.Connection")
dim rs : set rs = server.createObject("adodb.recordset")
dim sql
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &_
"myExcelFile.xls;" &_
"Extended Properties=""Excel 8.0;HDR=YES;"""
then you yould use just sql to insert your data...
the possible connectionstrings for excel are listed here
THE BELOW CODE IS TO INSERT INTO AN EXISTING EXCEL FILE. THIS IS WHAT YOU NEED.
<%
Option Explicit
' OPEN DATABASE
dim objConn,strConnection,objRS,strQuery
'Set objConn = New ADODB.Connection
set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("TEST.xls") & "; Extended Properties=Excel 8.0;"
objConn.Open strConnection
'Set objRS = New ADODB.Recordset
set objRS = Server.CreateObject("ADODB.Recordset")
set objRS.ActiveConnection = objConn
' This is to Select A1:A1 and open the recordset
strQuery = "SELECT * FROM A1:A1"
objRS.Open strQuery
' This is to insert into A1:A1 a value that says: testttest
strQuery = "insert into [A1:A1] values('testttest')"
' Close and destroy the Connection object.
objConn.Execute strQuery
objConn.Close
Set objRS=Nothing
Set objConn=Nothing
%>
TO UPDATE A SPECIFIC COLUMN
You can do this: See here: http://bytes.com/topic/asp-classic/answers/620074-update-existing-excel-file-using-asp-urgent
and also here: Update Excel Sheet (in Classic ASP/Vbscript)

Syntax error (missing operator) in query expression

I know it is a common error, but I still can't solve it myself.
What I am trying to do is I have a SELECT item called status that allow the user to choose their employment status, I want to simply get the result and update the user_table(access file) status cell.
Any reply will be greatly appreciated!
The Code is below:
<!--#include file="../conn/conn.asp"-->
<%
id=request.QueryString("id")
status=request.Form("status")
sql="select * from user_table where id="&id
set rs=conn.execute(sql)
sql="update user_table set Status='"+status+"' where id="&id
'response.Write sql
conn.execute(sql)
conn.close
response.Write "<script>alert('Change Sucessful!');</script>"
set conn=nothing
response.end()
%>
I think you may be having a problem with conn.execute(sql) as well as response.end()
To fix it, you need to do either:
conn.execute sql
or
Call conn.execute(sql)
But, yeah, you should follow other comments posted as your technique has security issues. You should consider changing it to use parameters:
<!--#include file="../conn/conn.asp"-->
<%
id = request.QueryString("id")
status = request.Form("status")
sql = "select * from user_table where id = #id"
Set cmd = CreateObject("ADODB.Command")
cmd.CommandText = sql
Set cmd.ActiveConnection = conn
cmd.Prepared = True
cmd.Parameters.Refresh
cmd.Parameters("#id") = id
Set rs = cmd.Execute
Set rs = nothing
Set cmd = nothing
sql = "update user_table set status = #status where id = #id"
Set cmd = CreateObject("ADODB.Command")
cmd.CommandText = sql
Set cmd.ActiveConnection = conn
cmd.Prepared = True
cmd.Parameters.Refresh
cmd.Parameters("#status") = status
cmd.Parameters("#id") = id
Set rs = cmd.Execute
Set rs = nothing
Set cmd = nothing
response.Write "<script>alert('Change Sucessful!');</script>"
Set conn = nothing
response.end
%>
I'm guessing conn.asp leaves conn open? otherwise you need to open it. Also, what shows when you uncomment the response.write sql line?
And, you are definitely opening yourself to hackers. You need to 'clean' anything that comes from a request.form or request.querystring (with at the very least, a replace(..., "'", "''"), or much better, use stored procedures instead of straight sql

Resources