473,386 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

retrieving document from SQL 2000 problem

Hi,

I hope anyone can help me with this problem.

I have a field of image type in a SQL 2000 database. I'm using this
code to insert a document:

Dim conn
Dim rs
Dim oStream

Session.Codepage = 65001
Response.Charset = "utf-8"

response.clear
response.expires = 0
response.buffer = true

'Response.ContentType = "application/pdf"
Response.ContentType = "application/ms-word"

Set conn = CreateObject("ADODB.Connection")
conn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist
Security Info=False;Initial Catalog=PBase;Data Source=BURKEN"

strSQL = "Select * From News where NEWS_ID=1"
Set oRS = CreateObject("ADODB.Recordset")
Call oRS.Open(strSQL, conn, 2, 2)

Set oStream = CreateObject("ADODB.Stream")
oStream.Type = 1
oStream.Open
oStream.LoadFromFile "C:\Inetpub\wwwroot\PB_Kansli\Files\luculli.do c"
oRS.Fields("NEWS_DATA").Value = oStream.Read
oStream.Close
Set oStream =nothing
oRS.Update
oRS.Close
Set oRS =nothing

conn.Close
Set conn = nothing
Data is put in the field and I'm using this code to retrieve it:

Set conn = CreateObject("ADODB.Connection")
conn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist
Security Info=False;Initial Catalog=PBase;Data Source=BURKEN"

strSQL = "Select * From News where NEWS_ID=1"
Set oRS = CreateObject("ADODB.Recordset")
Call oRS.Open(strSQL, conn, 2, 2)

Response.AddHeader "Content-Disposition", "inline;filename=test.doc"
Response.BinaryWrite oRS("NEWS_DATA")
oRS.Close
Set oRS =nothing

conn.Close
Set conn = nothing

The problem is that the output is nothing like the orginal. Instead of
a word document I get this:

Џࡱက>?ku?jx怀?????????????????????????? ?????????????????????????????????????????????????? ??????????????????????????????쥁3
??bjbjC?C?⃀!퀀!퀀v,???l\\\\??? ?vvv8? ??T
..⅀⅀⅀⅀?Ig sӈՈՈՈՈՈՈ$? ?
???{''"{{??\\⅀? ???{\⅀\8⅀ӈ?{ӈ??w\?w⅀օ
ೌ,̳Ɓ??v{Xww\$ 0T w* Ӈ(* w???\\\\

etc etc etc etc etc

What am I doing wrong?

Please help, I'm going crazy over this :-(

Thanks for your help,

Znubbe

Feb 17 '06 #1
5 2019
zn****@hotmail.com wrote:
Hi,

I hope anyone can help me with this problem.

I have a field of image type in a SQL 2000 database. I'm using this
code to insert a document:

Dim conn
Dim rs
Dim oStream

Session.Codepage = 65001
Response.Charset = "utf-8"

response.clear
response.expires = 0
response.buffer = true

'Response.ContentType = "application/pdf"
Response.ContentType = "application/ms-word"

Set conn = CreateObject("ADODB.Connection")
conn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist
Security Info=False;Initial Catalog=PBase;Data Source=BURKEN"

strSQL = "Select * From News where NEWS_ID=1"
Set oRS = CreateObject("ADODB.Recordset")
Call oRS.Open(strSQL, conn, 2, 2)

Set oStream = CreateObject("ADODB.Stream")
oStream.Type = 1
oStream.Open
oStream.LoadFromFile "C:\Inetpub\wwwroot\PB_Kansli\Files\luculli.do c"
oRS.Fields("NEWS_DATA").Value = oStream.Read
oStream.Close
Set oStream =nothing
oRS.Update
oRS.Close
Set oRS =nothing

conn.Close
Set conn = nothing
Data is put in the field and I'm using this code to retrieve it:

Set conn = CreateObject("ADODB.Connection")
conn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist
Security Info=False;Initial Catalog=PBase;Data Source=BURKEN"

strSQL = "Select * From News where NEWS_ID=1"
Why retrieve all the columns? It's usually a good idea to specify the column
you wish to retrieve...
Set oRS = CreateObject("ADODB.Recordset")
Call oRS.Open(strSQL, conn, 2, 2)

Response.AddHeader "Content-Disposition", "inline;filename=test.doc"
Response.BinaryWrite oRS("NEWS_DATA")
oRS.Close
Set oRS =nothing

conn.Close
Set conn = nothing

I think you need to use a Stream object. Try this:
If Not ors.eof then
Set FStream = Server.CreateObject("ADODB.Stream")
FStream.Type = adTypeBinary
FStream.Open
FStream.write rs("NEWS_DATA").Value
FStream.Position = 0
Response.AddHeader "Content-Length", FStream.size
Response.Charset = "UTF-8"
Response.BinaryWrite FStream.Read
Response.flush
end if

HTH,
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Feb 17 '06 #2
zn****@hotmail.com wrote:
Set oStream = CreateObject("ADODB.Stream")
oStream.Type = 1
oStream.Open
oStream.LoadFromFile "C:\Inetpub\wwwroot\PB_Kansli\Files\luculli.do c"
oRS.Fields("NEWS_DATA").Value = oStream.Read


I have not done it with this with a recordset, but I have done it with a
stored procedure. And in that case, it was necessary to set the value AND
size of the parameter. Consider this example:

CREATE PROCEDURE dbo.News_AttachDocument (
@ID INT,
@Data IMAGE,
@ContentType VARCHAR(50)
) AS
UPDATE News
SET NEWS_DATA = @Data,
CONTENT_TYPE = @ContentType
WHERE NEWS_ID = @ID
GO

To insert the data, use something like this. I will attempt to use objects
and names from your example:

Set CMD = Server.CreateObject("ADODB.Command")
Set CMD.ActiveConnection = conn 'Should already be open
CMD.CommandType = adCmdStoredProc
CMD.CommandText = "News_AttachDocument"
CMD.Parameters.Append(CMD.CreateParameter("@ID",ad Integer,adParamInput,4))
CMD.Parameters.Append(CMD.CreateParameter("@Data", adVarBinary,adParamInput,16))
CMD.Parameters.Append(CMD.CreateParameter("@Conten tType",adVarChar,adParamInput,50))
CMD.Parameters("@ID").Value = 1 'Your record ID
CMD.Parameters("@Data").Size = oStream.Size
CMD.Parameters("@Data").Value = oStream.Read()
CMD.Parameters("@ContentType").Value = 'Appropriate doctype
CMD.Execute()

Note that the important step here is setting both the size and value of the
blob parameter. You can then extract it with something along these lines:

Set RS = conn.Execute("SELECT NEWS_DATA, CONTENT_TYPE " _
"FROM News WHERE NEWS_ID = 1")

Response.ContentType = RS.Fields("CONTENT_TYPE").Value
Response.BinaryWrite(RS.Fields("NEWS_DATA").Value)

I have never had a problem doing it this way. There may be typos or other
syntax errors due to translation from my preferred JScript.

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Feb 17 '06 #3

Hi Bob,

Thanks for your reply, but unfortunately it is the same result :-(

Do you know if the insert action adds some kind of header to the data
that might corrupt it?

At the end of the gibberish it there is this text "Word-dokument
MSWordDocWord.Document.8" as well as "Microsoft Word 9.0s". Could it
be a unicode problem?

Best Regards,
Znubbe

Feb 17 '06 #4
zn****@hotmail.com wrote:
Hi Bob,

Thanks for your reply, but unfortunately it is the same result :-(

Do you know if the insert action adds some kind of header to the data
that might corrupt it?
Not in my experience. We use aspSmartUpload so perhaps my experience is not
typical.
I know a header is inserted when storing a Word Doc in an Access Memo field
but I've never seen an issue with SQL Server.
At the end of the gibberish it there is this text "Word-dokument
MSWordDocWord.Document.8" as well as "Microsoft Word 9.0s". Could it
be a unicode problem?

Maybe, but I doubt it.Sorry i can't help.

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Feb 17 '06 #5
Hi again,

I changed to this line:

Response.AddHeader "Content-Disposition",
"attachment;filename=test.doc"

and it worked like charm :-) Not sure why inline doesn't work though.

Feb 19 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chris Shipley | last post by:
I am trying to present a list of links on a page (Form) where each link opens a different picture gallery. I have the Form page which contains the links, a Gallery page, and several include files....
3
by: Kant | last post by:
Hi, i have a simple problem. i have a form with a lot's of number of Text and Hidden Fields. I just do a simple loop to get each value for each attribute. I have about more than 2000. if i do...
1
by: David Trivette | last post by:
I was wondering if anyone could help me with a MS Access 2002 issue I'm having. Problem - I created a db in Access 97 which worked just fine for several years. In the db the user can generate...
1
by: oliver james | last post by:
Having recently upgraded to Access 2002 at work, we have encountered the error message "Problem retrieving printer information for this object". Looking back through earlier posts, it appears that...
3
by: Susanne Klemm | last post by:
Hello! I use a procedure to insert a new row into a table with an identity column. The procedure has an output parameter which gives me the inserted identity value. This worked well for a long...
3
by: Harish | last post by:
I am buiding an application in ASP.Net 2.0 with C#. After installing corel wordperfect i am adding the reference into the application. Afetr adding reference interop.wordperfect.dll is added to the...
0
bmallett
by: bmallett | last post by:
First off, i would like to thank everyone for any and all help with this. That being said, I am having a problem retrieving/posting my dynamic form data. I have a form that has multiple options...
34
by: vpriya6 | last post by:
Hi guys, I am new to Ajax, xml and javascript. I want to know how can I retrieve data from xml and display in the html page? please help me out. suppose my xml file is customer.xml the code...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.