PDA

View Full Version : ASP file uploader into sql server using ado


tokmoh
10-12-2010, 06:31 PM
i dont know how to store file into sql, but i think the script must be like this..
i got an error that shown

Error Type:
ADODB.Recordset (0x800A0BB9)
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
/webpage/test.asp, line 19

anyone know what type of this error? how to solve it?

<%
dim objStream

set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1
objStream.Open
objStream.LoadFromFile("C:\t.txt")
objStream.close

dim conn, rs

set conn = server.createObject("adodb.connection")
conn.open "Provider=SQLOLEDB.1;Password=admin2009;Persist Security Info=True;User ID=sa;Initial Catalog=C:\WEBLOGON\APP_DATA\DATABASE.MDF;Data Source=T-BE715753D1694\SQLEXPRESS"

set rs = server.createObject("adodb.recordset")

conn.beginTrans

rs.Open "SELECT blobcolumn FROM blob WHERE id = 1", Conn, adOpenReadOnly, adLockOptimistic, adCmdText
rs.fields("blobcolumn").appendChunk stream.read
rs.update
rs.close

conn.commitTrans
%>

Old Pedant
10-12-2010, 07:00 PM
How do you expect to write to a recordset that you opened as adOpenReadOnly??? Not that it matters. You are using that parameter in the wrong spot in the open.

Further, when you update a record using ADO, you really need to update the *ENTIRE* record.

SO *PROBABLY* this code would work better. But NO GUARANTEES:

rs.Open "SELECT * FROM blob WHERE id = 1", Conn, adOpenStatic, adLockPessimistic
rs.fields("blobcolumn").appendChunk stream.read
rs.update
rs.close

Since you aren't *really* using chunks, why use appendChunk?? Why not simply

rs.fields("blobcolumn") = stream.read

But it wouldn't surprise me if that doesn't work. Just worth trying.