Solved

Can I store a word document in SQL database.

Posted on 2007-03-30
6
2,294 Views
Last Modified: 2012-06-22
Hi,
Can I store a word document in SQL database.

Thanx
0
Comment
Question by:CoolBuddha
6 Comments
 
LVL 1

Expert Comment

by:bdmadden
Comment Utility
Yes, you would want to make the datatype either "blob" or "binary" (depending on your SQL database), and save the entire file within a single field.  It would be equivalent to saving an image file in a database.  When you save the file in the database, you must ensure that the transfer is done in binary mode, not text mode (exactly how depends on what you're using to do this transfer); and when you pull out the data you also need to pull it out as binary and write the data to a file that will then be recognized by Word (use a .doc extension).
0
 
LVL 70

Expert Comment

by:KCTS
Comment Utility
Yes indeed. If you want to be able to search for text in the document within SQL make sure that 'Full Text Indexing' is enabled on the Database.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
Sure you can, but should you? and the answer in most cases is no.
0
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
LVL 7

Expert Comment

by:madgett
Comment Utility
The way I store a word document in SQL Server 2005 is by storing it in it's native WordML format, which is xml. Use the XML datatype on the field, now you can get absolutely everything about that word document using XSLT or native .NET xml parsing methods.
0
 
LVL 3

Accepted Solution

by:
ieciep earned 125 total points
Comment Utility
try
        {
            byte[] bytThumb = System.IO.File.ReadAllBytes(SourceFile);
            size = bytThumb.Length.ToString();
            SourceF = SourceFile;
            SqlConnection sqlConnection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["CONNECTION_STRING_SERVER"].ToString());
            SqlCommand command = sqlConnection.CreateCommand();
            if (sqlConnection.State == ConnectionState.Closed)
            {
                sqlConnection.Open();
            }
            command.CommandText = "UPDATE  table FILE_DATA =@FILE_DATA WHERE PUBLICATION_ID=" + DocumentID;
            SqlParameter param = new SqlParameter("@FILE_DATA", SqlDbType.Image);
            if (bytThumb == null)
            {
                param.Value = DBNull.Value;
            }
            else
            {
                param.Value = bytThumb;
            }
            command.Parameters.Add(param);
            command.ExecuteNonQuery();
            sqlConnection.Close();
        }
        catch (Exception xp)
        {
            throw xp;
        }
0
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
I realize you are new here, however you may wnat to re-read the EE Guidelines on grading at:
What's the right grade to give?
http://www.experts-exchange.com/help.jsp#hi73

And in particular this section:

<quote>
C: Because Experts' reliability are often judged by their grading records, many Experts would like the opportunity to clarify if you have questions about their solutions. If you have given the Expert(s) ample time to respond to your clarification posts and you have responded to each of their posts providing requested information; or if the answers, after clarification, lack finality or do not completely address the issue presented, then a "C" grade is an option. You also have the option here of just asking Community Support to delete the question.
Remember, the Expert helping you today is probably going to be helping you next time you post a question. Give them a fair chance to earn an 'Excellent!' grade and they'll provide you with some amazing support. It's also true that a "C" is the lowest grade you can give, and the Experts know that -- so use it judiciously.

The use of a C in a vindictive manner is likely to be changed by a Moderator. You may not like the answer you get, and in some cases, and you may not like the way it is delivered, but if it is deemed to be accurate, no less than a B is an acceptable grade.

</quote>

Also, see here:
Can I get a grade changed?
http://www.experts-exchange.com/help.jsp#hi18

As it stands now your record reads as follows:
Last 10 Grades Given: C
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now