Solved

Can I store a word document in SQL database.

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

Thanx
0
Comment
Question by:CoolBuddha
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 1

Expert Comment

by:bdmadden
ID: 18827833
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
ID: 18828152
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
ID: 18828936
Sure you can, but should you? and the answer in most cases is no.
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 7

Expert Comment

by:madgett
ID: 18831256
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
ID: 18842394
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
ID: 18900205
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.

752 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