Solved

Can I store a word document in SQL database.

Posted on 2007-03-30
6
2,305 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

622 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