I am using T-SQL and Microsoft Management Studio 2008 R2. I want to create a database in which I can store video files.
After google search and some reading I have learned that there is a option to use "File Stream Enable Database". It was said that this kind of database should be used only when your files are larger then 2MB. I want to store video files, so I think this is suitable for my goals.
Please, give me more information about the main difference in using BLOB and FileStream Enable database or just to store the files in a given directory and to save only the url in the database table column?
Thanks in advance.
Filestream was an interesting change when it came in for me; the bit that suprised me was Full Text Search was taken out of the operating system because it caused issues; but file stream put it back because Blobs caused issues.
Using Filestream is basically transparent to your application and it even backs the files up as if they were in the database - and thats the big benefit or cost over the save in database v save pointer in database.
You can insert files the same way as you did before and you can read them back in SQL in exactly the same way. The difference and benefit is that that SQL can take advantage of Windows system cache for reading and files saving its own resources to make other queries run quicker.
Please, give me more information about the main difference in using BLOB and FileStream Enable
database
The feature you call for is "FileStream" not "FileStream enable".
Some blogs are also around, like http://blogs.msdn.com/b/rdoherty/archive/2007/10/12/getting-traction-with-sql-server-2008-filestream.aspx
At kleast try reading the documentation before running around and have other people do your basic groundwork.
Related
Can anyone advise in detail what does the varbinary(max) value represent if say a BLOB file (.pdf) is stored in the file system through the filestream attribute in sql server?
And how does it get copied across databases on different servers by using the usual T-SQL queries?
Many thanks.
Best regards,
Storing BLOB data using a FILESTREAM setup enables you to store your documents on disk while keeping your document's reference information in the database. Sometimes it is advised to use this approach if your file storage solution is cheap while your database storage is not, but it really depends on your requirements.
If you are working with small BLOB files, it might be better to leave the FILESTREAM setup alone as it comes with some overhead configuring and maintaining this. For instance in your comment's example to copy over data from one server to another.
I have SQL Server 2012 and started looking into Filestream as a way to link "attachments" (> 1 GB) such as Excel documents and PDF files to database table records. While I have been successful in finding the "hello world" T-SQL examples that allow me to do some rudimentary tasks (enable Filestream, create table with Filestream column, insert row, etc.) I also encounter "beware" statements.
Is Filestream really as temperamental and full of "gotchas" as I the variously placed forum writings suggest, or is it straight forward and with a least predictable quriks?
Thank you for any insight
I would recommend using filetable which is implemented using filestream and its really neat enhancement, it preserves functionality of filestream but in contrast to filestream it can be configured to also allow accessing files outside db engine. For example, you can allow IIS to use those files directly. In production in big telecom company from 2013, flawless!
P.S. this is maybe more suitable for comment but I don't have reputation to write it :)
There are many times that I wanted to save an image to an SQL Server. I have read some practices for saving images :
1) upload and save image to server, save the path inside the table
2) save image as binary
3) save image as base64 string
4) using BLOB(i haven't researched how it works)
Do you know which "way" is faster when you request from server an image?
Do you know which "way" is better so as not to make SQL server slower?
Do you know any other "way" which is better from the above?
Thanks!
Microsoft has done some research on this topic and has concluded that it depends on the size of your image. If most of your images are < 256Kb, you should probably use VARBINARY. On the other hand, if they are above 1Mb, then you should use a FILESTREAM (which is usually stored on the filesystem outside the database file).
If your images are linked to other data, it's often useful to separate the records itself from the images into different tables (i.e. create an Images table) so that the table with the data remains small and easy to manipulate.
Pls note that there is no “best” way universally but only the one that suits your specific need the most.
“Do you know which "way" is faster when you request from server an image?” – in this case #1 because you essentially store image in the file system and only retrieve image path from database.
“Do you know which "way" is better so as not to make SQL server slower?” – again #1 because it has to deal with less data. It’s easier for SQL Server to retrieve varchar representing path where image is stored than to retrieve the image itself in whatever form.
No.1 is the simplest and probably easiest to setup but pls note that there are disadvantages:
if some image is deleted from file system SQL Server doesn’t have a clue that this happened
When you delete row from SQL Server you also need to delete image from file system (if you want to keep things clear ;))
You also need to backup data from file system and not only SQL Server database
I have a standard WinForms application that connects to a SQL Server. The application allows users to upload documents which are currently stored in the database, in a table using an image column.
I need to change this approach so the documents are stored as files and a link to the file is stored in the database table.
Using the current approach - when the user uploads a document they are shielded from how this is stored, as they have a connection to the database they do not need to know anything about where the files are stored, no special directory permissions etc are required. If I set up a network share for the documents I want to avoid any IT issues such as the users having to have access to this directory to upload to or access existing documents.
What are the options available to do this? I thought of having a temporary database where the documents are uploaded to in the same way as the current approach and then a process running on the server to save these to the file store. This database could then be deleted and recreated to reclaim any space. Are there any better approaches?
ADDITIONAL INFO: There is no web server element to my application so I do not think a WCF service is possible
Is there a reason why you want to get the files out of the database in the first place?
How about still saving them in SQL Server, but using a FILESTREAM column instead of IMAGE?
Quote from the link:
FILESTREAM enables SQL Server-based applications to store unstructured
data, such as documents and images, on the file system. Applications
can leverage the rich streaming APIs and performance of the file
system and at the same time maintain transactional consistency between
the unstructured data and corresponding structured data.
FILESTREAM integrates the SQL Server Database Engine with an NTFS file
system by storing varbinary(max) binary large object (BLOB) data as
files on the file system. Transact-SQL statements can insert, update,
query, search, and back up FILESTREAM data. Win32 file system
interfaces provide streaming access to the data.
FILESTREAM uses the NT system cache for caching file data. This helps
reduce any effect that FILESTREAM data might have on Database Engine
performance. The SQL Server buffer pool is not used; therefore, this
memory is available for query processing.
So you would get the best out of both worlds:
The files would be stored as files on the hard disk (probabl faster compared to storing them in the database), but you don't have to care about file shares, permissions etc.
Note that you need at least SQL Server 2008 to use FILESTREAM.
I can tell you how I implemented this task. I wrote a WCF service which is used to send archived files. So, if I were you, I would create such a service which should be able to save files and send them back. This is easy and you also must be sure that the user under which context the WCF service works has permission to read write files.
You could just have your application pass the object to a procedure (CLR maybe) in the database which then writes the data out to the location of your choosing without storing the file contents. That way you still have a layer of abstraction between the file store and the application but you don't need to have a process which cleans up after you.
Alternatively a WCF/web service could be created which the application connects to. A web method could be used to accept the file contents and write them to the correct place, it could return the path to the file or some file identifier.
We have stored all media in Sql Filestream, but now we'll need Video and Audio streaming... Will this be possible with Sql Filestream or will I have to take all of the Video and Audio out of the database?
Which technology would you use to enable Video/Audio Streaming?
WebORB
FluorineFX
Wowza (way better I think than the first two)
IIS Media (haven't looked into this yet)
When using IIS Media its not possible to store the data in a SQL Fielstream.
For further details check here.
It's possibly very similar with the rest of your suggested solutions, since all of them need to re encode the material to enable streaming (if its not in the necessary format already).
You actually have 2 problems:
Re encoding the videos into a format
that enables you to stream it via
the server platform you choose, just
for this part you need to extract
the files from the db since the
encoding tools can't be fed from a
database, even if its a SQL FileStream
Store the encoded files
somewhere the media servers can
access them, again they don't allow
a SQL Server as a data soure, they
probably have their own storing
infrastructure or use the file
system.
Conclusion:
The FileStream is extremely helpful when you have full control over server/client, but sadly not in your case.
You will probably have to extract all files from the DB.
The FileTable feature in SQL Server "Denali" (not yet released) is designed specifically for this scenario (amongst others).
There's a good overview link here: Using FileTables to Manage Unstructured FILESTREAM Data.
This will allow you to directly access and play these files through a provided UNC path without requiring any changes to the application, so you can use any of the above mentioned streaming servers.