473,548 Members | 2,704 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Codepag e = 65001
Response.Charse t = "utf-8"

response.clear
response.expire s = 0
response.buffer = true

'Response.Conte ntType = "applicatio n/pdf"
Response.Conten tType = "applicatio n/ms-word"

Set conn = CreateObject("A DODB.Connection ")
conn.Open "Provider=SQLOL EDB.1;Integrate d Security=SSPI;P ersist
Security Info=False;Init ial Catalog=PBase;D ata Source=BURKEN"

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

Set oStream = CreateObject("A DODB.Stream")
oStream.Type = 1
oStream.Open
oStream.LoadFro mFile "C:\Inetpub\www root\PB_Kansli\ Files\luculli.d oc"
oRS.Fields("NEW S_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("A DODB.Connection ")
conn.Open "Provider=SQLOL EDB.1;Integrate d Security=SSPI;P ersist
Security Info=False;Init ial Catalog=PBase;D ata Source=BURKEN"

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

Response.AddHea der "Content-Disposition", "inline;filenam e=test.doc"
Response.Binary Write 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:

Џࡱက>?k u?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 2036
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.Codepag e = 65001
Response.Charse t = "utf-8"

response.clear
response.expire s = 0
response.buffer = true

'Response.Conte ntType = "applicatio n/pdf"
Response.Conten tType = "applicatio n/ms-word"

Set conn = CreateObject("A DODB.Connection ")
conn.Open "Provider=SQLOL EDB.1;Integrate d Security=SSPI;P ersist
Security Info=False;Init ial Catalog=PBase;D ata Source=BURKEN"

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

Set oStream = CreateObject("A DODB.Stream")
oStream.Type = 1
oStream.Open
oStream.LoadFro mFile "C:\Inetpub\www root\PB_Kansli\ Files\luculli.d oc"
oRS.Fields("NEW S_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("A DODB.Connection ")
conn.Open "Provider=SQLOL EDB.1;Integrate d Security=SSPI;P ersist
Security Info=False;Init ial Catalog=PBase;D ata 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("A DODB.Recordset" )
Call oRS.Open(strSQL , conn, 2, 2)

Response.AddHea der "Content-Disposition", "inline;filenam e=test.doc"
Response.Binary Write 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.CreateOb ject("ADODB.Str eam")
FStream.Type = adTypeBinary
FStream.Open
FStream.write rs("NEWS_DATA") .Value
FStream.Positio n = 0
Response.AddHea der "Content-Length", FStream.size
Response.Charse t = "UTF-8"
Response.Binary Write 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("A DODB.Stream")
oStream.Type = 1
oStream.Open
oStream.LoadFro mFile "C:\Inetpub\www root\PB_Kansli\ Files\luculli.d oc"
oRS.Fields("NEW S_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_Attach Document (
@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.CreateOb ject("ADODB.Com mand")
Set CMD.ActiveConne ction = conn 'Should already be open
CMD.CommandType = adCmdStoredProc
CMD.CommandText = "News_AttachDoc ument"
CMD.Parameters. Append(CMD.Crea teParameter("@I D",adInteger,ad ParamInput,4))
CMD.Parameters. Append(CMD.Crea teParameter("@D ata",adVarBinar y,adParamInput, 16))
CMD.Parameters. Append(CMD.Crea teParameter("@C ontentType",adV arChar,adParamI nput,50))
CMD.Parameters( "@ID").Valu e = 1 'Your record ID
CMD.Parameters( "@Data").Si ze = oStream.Size
CMD.Parameters( "@Data").Va lue = 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("S ELECT NEWS_DATA, CONTENT_TYPE " _
"FROM News WHERE NEWS_ID = 1")

Response.Conten tType = RS.Fields("CONT ENT_TYPE").Valu e
Response.Binary Write(RS.Fields ("NEWS_DATA").V alue)

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.AddHea der "Content-Disposition",
"attachment;fil ename=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
1788
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. Each include file displays a different gallery. Clicking on a link submits a value identifying the chosen gallery to the Gallery page. The Gallery...
3
1609
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 something simple like : for (var i=0; i<2000; i++) aValue = i+10;
1
9915
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 reports straight to a printer after a query has run. The user of this db just got a new computer with Windows XP and Access 2002. Now when the...
1
1897
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 this is a common problem with Access 2002, but that no definitive solution has been posted. I also notice that the last time it was posted was...
3
2836
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 time. Now the identity value is over 700.000 and I get errors whiles retrieving the inserted identitiy value. If I delete rows and reset the identity...
3
16247
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 Bin folder. After creating the object of Wordperfect.Perfectscript i am opening the wordperfect file and then run the wordperfect macro. In...
0
3371
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 within options. I have everything being dynamically named from the previously dynamically named element. (I hope this makes sense.) I am not able to...
34
2536
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 is below: <CUSTOMER>
0
7444
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7711
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7954
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7805
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6039
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5367
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5085
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1932
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1054
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.