Streaming a big file directly to the database
I'm using a WCF application to save a file received via streaming to the database. I interact with 开发者_StackOverflowmy database using LINQ to SQL. I need a way to insert any data I receive automatically to the database.
Call a stored procedure that does an insert. If that isn't what you are looking for be more specific in the question.
Linq-to-SQL isn't the best choice when inserted large items into a database table. It's well suited for "normal" records like addresses and so on - but large files, you're probably better off storing those into the database directly using straight ADO.NET.
What version of SQL Server are you using in the background? If you're on SQL Server 2008, and if your files are often or even typically larger than 1 MB in size, you might want to investigate the FILESTREAM feature. This would allow you to stream the data into a SqlFileStream
object.
Otherwise, Woot4Moo's idea of a stored proc to handle the storing into a BLOB column should work just fine (or an inline SQL query, if you and your DBA are OK with that).
精彩评论