Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Can I store a word document in SQL database.

Posted on 2007-03-30
6
Medium Priority
?
2,307 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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
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 250 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

How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

Question has a verified solution.

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

Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
What we learned in Webroot's webinar on multi-vector protection.
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

715 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