473,383 Members | 1,864 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,383 software developers and data experts.

Storing the content of doc\pdf into MS SQL2005 DB

7
Friends,
I need to read the content of doc\pdf and store it in DB. I am using fstram logic to do this. Currently it only working for txt files. I am not sure whether fstream handles doc\pdf. But when I read I am able to see some values (I don't know whether its junk) in variable. The DB column type is 'text'. Can any suggest me some resolution for this???
Jul 9 '08 #1
6 1505
Banfa
9,065 Expert Mod 8TB
doc format is a binary format so when using your fstream you need to make sure that you are doing a binary read and when storing it in the data base you need to store in a field with a binary type like image
Jul 9 '08 #2
San07
7
doc format is a binary format so when using your fstream you need to make sure that you are doing a binary read and when storing it in the data base you need to store in a field with a binary type like image
Banfa,
Ya I am considering it as a binary. I am using the fstream attributes ios::in|ios::binary|ios::ate, but still its not reading the doc completely. Its failing somewhere while reading the header info of doc. Only some 8 char are read.
following is the method I am using to read it

ifstream::pos_type size;
char * pszBuffer;
ifstream file (strFileName, ios::in|ios::binary|ios::ate);
if (file.is_open())
{
size = file.tellg();
pszBuffer = strAttachmentBuffer.GetBufferSetLength(size);
file.seekg (0, ios::beg);
file.read (pszBuffer, size);
file.close();
}
Any idea why its not reading completely? Any other attributes I need to add??
Jul 9 '08 #3
Banfa
9,065 Expert Mod 8TB
GetBufferSetLength looks like it's a member of CSimpleStringT.

If so then you need to change that, CSimpleStringT is for holding strings, you are not dealing with string data you want to hold an array of binary bytes. Something like CByteArray.
Jul 9 '08 #4
San07
7
GetBufferSetLength looks like it's a member of CSimpleStringT.

If so then you need to change that, CSimpleStringT is for holding strings, you are not dealing with string data you want to hold an array of binary bytes. Something like CByteArray.
Ya that true. But I am trying to read & hold the value in pszBuffer, which is a char pointer. The value is not read here only. Now what I am really confused is whether fstream can read the doc\pdf ?
I am trying to read a word Doc\pdf.
Jul 10 '08 #5
Banfa
9,065 Expert Mod 8TB
Ya that true. But I am trying to read & hold the value in pszBuffer, which is a char pointer. The value is not read here only. Now what I am really confused is whether fstream can read the doc\pdf ?
I am trying to read a word Doc\pdf.
I see no reason why it wouldn't but if you are worried read it and then write it immediately to convince yourself.

There is nothing special about doc/pdf, it's just another binary file format (well 2) and fstream can read binary data when set-up correctly (which you seem to have done).
Jul 10 '08 #6
San07
7
I see no reason why it wouldn't but if you are worried read it and then write it immediately to convince yourself.

There is nothing special about doc/pdf, it's just another binary file format (well 2) and fstream can read binary data when set-up correctly (which you seem to have done).

Banfa,
Thanks for ur time nd suggestions.
k the problem of writing a doc\pdf is not exactly after reading. Immediately, after reading if I try to write into a file, its working file. But I need to store the data into SQL 2005 DB. If I try to retreive the content from DB its failing to write it back.

What exactly happening is when I read a doc file(Ex 160kb file) , the content in the char pointer will be "ÐÏࡱá" (instead of "ÐÏࡱá >  þÿ.....") and it will be stored in DB as it is and when I retreive it back it says the size is 8 and copiesthe same in file.
So, I immediately after reading the doc, I wrote the content the content to a text file. Then I edited the text file (I deleted the white spaces after the 8th digit and till the symbol '>' but still there were lot of spaces in the file) To my surprise when I read back from DB the content was 160kb(that means the file is storing the complete info). But anyway the file was corrupted since we had manually modified the header content.
1. Is there any attribute I am missing bcoz of which I am failing to read the header completely?
2. Do I need to use anything more like serialization?


In DB(MS-SQL 2005) the column which I are using is of Data_Type 'text' (which has the capacity to hold upto 2GB)
Jul 10 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Brian Burgess | last post by:
Hi all, Anyone know of any special issues with storing cookies with ASP? I'm trying this with two browsers: One is IE 6.0 with cookies set to 'prompt'. This has been working properly as any...
2
by: ad | last post by:
The user of my asp.net program use Sql2005 or Sql2005 express as database, both are possible. I have try both version of data base, I found: If I use Sql2005 express, the Data Source in...
2
by: Robert Hanson | last post by:
I am new to the asp.net application building and I have read the information regarding the storing of information using session vs cookies vs viewstate. I am asking for suggestions/guidance as to...
2
by: ad | last post by:
Hi, As title, After I install Sql2005 SepCTP, can I install VS2005 Beta2 in the same machine?
1
by: r1100r98 | last post by:
I am having a problem moving the data from a datatable to the SQL2005 table (using VB2005). See code below. The SQL2005 table is empty, the datatable is being filled from a text file, not from...
5
by: Mike | last post by:
I'm having trouble accessing SQL2005 Standard Edition as a second instance of SQL Server where the first instance is SQL 2000 Enterprise Edition. I installed SQL 2005 as a named instance...
9
by: Nemisis | last post by:
Hi everyone, hope your all looking forward to xmas. I am setting up a Sql2005 database on a Windows Server, running Windows Server 2003. The database is going to be accessed via users using an...
3
by: Michael Schöller | last post by:
Hello, First of all english is not my natural language so please fogive me some bad mistakes in gramatic and use of some vocables :). I have a great problem here. Well I will not use it...
0
by: nic829 | last post by:
Hi, I was upgrading a instance from SQL2000 to SQL2005. During SQL2005 setup I accidently allow the files to be installed in C drive, but I should have them all installed in D drive. My databases...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.