Solved

Can I store a word document in SQL database.

Posted on 2007-03-30
6
2,299 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
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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

770 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