August 10, 2008 at 7:10 am
I am trying to store word docs/image on sql server using BLOB. Is there anyway we can implement this. Please advice.
August 10, 2008 at 10:04 am
Use the varbinary(max) data type. Also, look at SQO Server 2008 and filestream objects, which will work a lot better when storing this kind of data.
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
August 10, 2008 at 10:23 am
Thank You for your response. Could you please give me more inputs on how I can implement this on SQL 2005.
August 10, 2008 at 10:49 am
I have absolutely no idea on what additional information you need. How you implement storing image data in SQL Server all depends upon what you need to do.
For example, if you are going to be storing a lot of documents (thousands) - you probably wouldn't want to store them in the database. You probably would want to store them in the file system and only store a link to the document.
However, if you can implement this on SQL Server 2008 - you could setup the filestream partition for your database and define the column with the filestream attribute and SQL Server will take care of storing the data in the file system.
For further information on filestream you can lookup the topic on Books Online.
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
August 10, 2008 at 5:37 pm
I believe the question is how to load the Word file into the VARCHAR(MAX) element.
And, yes, I agree... it's probably better to store the name of the file in a table instead of the file itself. Still, how would you load the document into a VARCHAR(MAX) element?
--Jeff Moden
Change is inevitable... Change for the better is not.
August 10, 2008 at 6:06 pm
Jeff Moden (8/10/2008)
I believe the question is how to load the Word file into the VARCHAR(MAX) element.And, yes, I agree... it's probably better to store the name of the file in a table instead of the file itself. Still, how would you load the document into a VARCHAR(MAX) element?
Not sure what you are asking here. You use an INSERT statement and insert the data into the table, nothing special.
Now, if you are asking about using FILESTREAM - that I do not know yet. I have not had the opportunity to work with it yet, so I am not sure if there is anything you need to do other than define the varbinary column with the filestream attribute (after creating the filestream partition, of course).
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
August 10, 2008 at 9:50 pm
No... the question is simple... you have a Word doc sitting in a directory somewhere... how do you load that file into a VARCHAR(Max) column (only one row, of course) in a database table?
--Jeff Moden
Change is inevitable... Change for the better is not.
August 10, 2008 at 9:57 pm
This is not a task I need to do, it is for learning purpose. I happened to read that word docs/images can be stored in sql server using BLOB. I was trying to implement it, but was not exactly sure how... So it would be really enough that i get a method by which I can store atelast 1 word doc/ image 🙂
August 10, 2008 at 10:21 pm
Ah ha! I knew I had an example squirreled away somewhere. Of course, you can do it with a GUI using ADO and all that... but here's a way to do it directly from a file...
CREATE TABLE dbo.SomeTable (ID INT IDENTITY(1,1), MyDoc VARBINARY(MAX))
INSERT INTO dbo.SomeTable(MyDoc)
SELECT * FROM OPENROWSET(BULK N'd:\somepath\somefilename.doc', SINGLE_BLOB) AS MyDoc
--Jeff Moden
Change is inevitable... Change for the better is not.
August 10, 2008 at 10:38 pm
Just what I needed. Thanks a lot for Jeff... 🙂
August 10, 2008 at 10:45 pm
...and thanks for the feedback! 🙂
--Jeff Moden
Change is inevitable... Change for the better is not.
August 11, 2008 at 7:44 am
Jeff,
Here comes another question. I just did what you have mentioned in the Script for storing file. It worked fine. I inserted a doc file in database. Now, how do you retrieve that file? when you run select statement like
SELECT * FROM dbo.SomeTable
it gives you an Hexadecimal info for the MyDoc column of the table. So how do you get original file back?
Chintan
August 11, 2008 at 6:46 pm
THAT, my friend, it why I recommend only storing the file name and not the file itself. 😛
You either have to capture the info in a variable in a GUI and then open Word and pass that whole mess to it (I believe... I'm no pro on the GUI side) or you have to output that mess to a file again. I've never tried that because I always save just the file name in the table. 😀 I believe you can do it by creating an empty file (perhaps using xp_CmdShell) and then inserting into the text file using OPENROWSET again but places reversed.
Sorry I don't know for sure because I just don't do it this way... in fact, I don't allow my developers to store files in the database at all.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 11, 2008 at 7:08 pm
Hi jeff,
That was informative...is ther a way using sql query to retrive the doc,image,pdf from the sql server tables to local computer with out using any ADO or front end tools.
Thanks in advance
August 11, 2008 at 7:10 pm
Hi Jeff,
can u please let me know similar query to retrive doc, image,pdf files stored in sql server tables.
Thanks in advance
Viewing 15 posts - 1 through 15 (of 21 total)
You must be logged in to reply to this topic. Login to reply