<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Zach Skyles Owens : FILESTREAM</title><link>http://blogs.msdn.com/zowens/archive/tags/FILESTREAM/default.aspx</link><description>Tags: FILESTREAM</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>TechEd 2008 Developers - Data Platform Keynote EDM/SSDS/SQL Data Types</title><link>http://blogs.msdn.com/zowens/archive/2008/06/05/teched-developers-data-platform-keynote-edm-ssds-sql-data-types.aspx</link><pubDate>Thu, 05 Jun 2008 19:46:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8575701</guid><dc:creator>ZachSkylesOwens</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/zowens/comments/8575701.aspx</comments><wfw:commentRss>http://blogs.msdn.com/zowens/commentrss.aspx?PostID=8575701</wfw:commentRss><description>&lt;p&gt;&lt;em&gt;By &lt;a href="http://blogs.msdn.com/zowens" target="_blank"&gt;Zach Skyles Owens&lt;/a&gt;&lt;/em&gt;&lt;/p&gt; &lt;p&gt;One of the biggest challenges we faced when designing this demo was trying to make the breadth of Microsoft's Data Platform technologies easily understandable in 5 minutes.&amp;nbsp; The major architecture components are &lt;a href="http://www.microsoft.com/sqlserver/2008/en/us/default.aspx" target="_blank"&gt;SQL Server 2008&lt;/a&gt;, &lt;a href="http://www.microsoft.com/sql/dataservices/default.mspx" target="_blank"&gt;SQL Server Data Services (SSDS)&lt;/a&gt;, &lt;a href="http://www.microsoft.com/sql/editions/compact/default.mspx" target="_blank"&gt;SQL Server Compact&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/sync/default.aspx" target="_blank"&gt;Sync&lt;/a&gt;; which I &lt;a href="http://blogs.msdn.com/zowens/archive/2008/06/03/teched-2008-developers-data-platform-keynote-demo-architecture.aspx" target="_blank"&gt;outlined in a previous post&lt;/a&gt;.&amp;nbsp; We've been following the blogosphere as closely as possible and, understandably so, one of the areas we've seen a bit of confusion around is the type support and conversion between the Entity Data Model, SSDS and SQL Server 2008. &lt;/p&gt; &lt;p&gt;There are a lot of moving parts here so I'll do my best at explaining how everything was integrated and how we got around some of the differences in type support of the data platform technologies.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Web Application&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/zowens/WindowsLiveWriter/TechEdDevelopersDataPlatformKeynoteEDMSS_AFB7/image_6.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="150" alt="image" src="http://blogs.msdn.com/blogfiles/zowens/WindowsLiveWriter/TechEdDevelopersDataPlatformKeynoteEDMSS_AFB7/image_thumb_2.png" width="244" align="right" border="0"&gt;&lt;/a&gt; Bloggers use this application to submit geo-tagged articles and images which are stored in SSDS.&amp;nbsp; We embedded a &lt;a href="http://dev.live.com/virtualearth/sdk/" target="_blank"&gt;Virtual Earth&lt;/a&gt; control which the users use to manually geo-tag their content.&amp;nbsp; Those who have been following SSDS closely may have noted that SSDS does not currently support blob storage or spatial types.&amp;nbsp; &lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;em&gt;Blob Storage in SSDS&lt;/em&gt; - This is the number one feature that customers are asking for right now with SSDS.&amp;nbsp; Until SSDS supports blobs our current workaround was to &lt;a href="http://en.wikipedia.org/wiki/Base64" target="_blank"&gt;Base64 Encode&lt;/a&gt; the images for storage in SSDS.  &lt;li&gt;&lt;em&gt;Spatial Storage in SSDS&lt;/em&gt; - Currently SSDS does not have support for Spatial types.&amp;nbsp; This was an easy work around for us by converting the spatial POINT coordinates to the &lt;a href="http://en.wikipedia.org/wiki/Well-known_text" target="_blank"&gt;Well Known Text (WKT)&lt;/a&gt; format and storing them as text.&amp;nbsp; &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;strong&gt;Mobile Application&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/zowens/WindowsLiveWriter/TechEdDevelopersDataPlatformKeynoteEDMSS_AFB7/image_4.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="226" alt="image" src="http://blogs.msdn.com/blogfiles/zowens/WindowsLiveWriter/TechEdDevelopersDataPlatformKeynoteEDMSS_AFB7/image_thumb_1.png" width="146" align="right" border="0"&gt;&lt;/a&gt; In this scenario we are also using a Windows Mobile device that allows bloggers to submit photos which are automatically sent to SSDS via the Microsoft Sync Framework.&amp;nbsp; Here are some key points:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;A SQL Server Compact database stores the application's meta-data  &lt;li&gt;Images are stored on the device's file system  &lt;li&gt;Geo-tagging is pulled directly from the GPS enabled device.&amp;nbsp; The app caches the last known GPS coordinates in case of lack of GPS connectivity.  &lt;li&gt;The Sync provider running on the device converts the geo-data to WKT and the image to Base64 text as in the web app&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;strong&gt;Sync from SSDS to SQL Server&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/zowens/WindowsLiveWriter/TechEdDevelopersDataPlatformKeynoteEDMSS_AFB7/sync2_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="77" alt="sync2" src="http://blogs.msdn.com/blogfiles/zowens/WindowsLiveWriter/TechEdDevelopersDataPlatformKeynoteEDMSS_AFB7/sync2_thumb.png" width="75" align="left" border="0"&gt;&lt;/a&gt; Our application uses a powerful WPF desktop application connected to a local SQL Server 2008 database.&amp;nbsp; Since SQL Server 2008 supports Spatial we have the ability to run high performance spatial queries which aren't currently possible in SSDS.&amp;nbsp; FILESTREAM allows us to use the high-performance of the file system for binary file storage along with transactional consistency and great manageability of the database.&amp;nbsp; Type conversion here was very simple and outlined below:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;em&gt;Sync and FILESTREAM&lt;/em&gt; - The Sync Provider sitting on our SQL Server database pulls the Base64 binary data from SSDS and inserts it into a varbinary(max) FILESTREAM column in our database.  &lt;li&gt;&lt;em&gt;Sync and Spatial&lt;/em&gt; - This Sync Provider inserts the WKT POINT data into a SQL Server GEOGRAPHY type.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;strong&gt;EDM, Spatial and FILESTREAM&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&amp;nbsp; &lt;a href="http://blogs.msdn.com/blogfiles/zowens/WindowsLiveWriter/TechEdDevelopersDataPlatformKeynoteEDMSS_AFB7/image_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="186" alt="image" src="http://blogs.msdn.com/blogfiles/zowens/WindowsLiveWriter/TechEdDevelopersDataPlatformKeynoteEDMSS_AFB7/image_thumb.png" width="244" align="right" border="0"&gt;&lt;/a&gt;&lt;a href="http://blogs.msdn.com/blogfiles/zowens/WindowsLiveWriter/TechEdDevelopersDataPlatformKeynoteEDMSS_AFB7/image_8.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="147" alt="image" src="http://blogs.msdn.com/blogfiles/zowens/WindowsLiveWriter/TechEdDevelopersDataPlatformKeynoteEDMSS_AFB7/image_thumb_3.png" width="244" align="right" border="0"&gt;&lt;/a&gt;Our WPF application uses the &lt;a href="http://msdn.microsoft.com/en-us/library/bb399572.aspx" target="_blank"&gt;Entity Data Model (EDM)&lt;/a&gt; to provide the application developers with a more natural business representation of the data. This allows the database model and application data model to evolve independently. Currently the EDM has limited support for FILESTREAM and does not natively support the new SQL Server 2008 Spatial types (GEOGRAPHY and GEOMETRY).&amp;nbsp; These were also very easy to work around in the following ways.&lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;em&gt;EDM and FILESTREAM&lt;/em&gt; - Currently the EDM treats FILESTREAM in the same way it treats any other varbinary(max) column.&amp;nbsp; You get the transaction consistency and manageability of the database.&amp;nbsp; It interacts with the FILESTREAM data through T-SQL so you don't get the Win32 streaming performance that FILESTREAM has the ability to provide.&amp;nbsp; If that type of read/write performance is needed you can easily write a section of code that interacts with traditional database connections and SQL.  &lt;li&gt;&lt;em&gt;EDM and Spatial&lt;/em&gt; - Currently the EDM does not support the new Spatial types.&amp;nbsp;&amp;nbsp; Our WPF application had two main requirements for Spatial: high performance queries and showing the Spatial meta-data.&amp;nbsp; We wrote a stored procedure for the queries and mapped a calculated column which converted the spatial data into WKT for displaying the meta-data.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;There were definitely some things that we had to consider when building this application but in the end none were major barriers.&amp;nbsp; The application works great and was an enjoyable development experience.&amp;nbsp; &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8575701" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/zowens/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://blogs.msdn.com/zowens/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/zowens/archive/tags/FILESTREAM/default.aspx">FILESTREAM</category><category domain="http://blogs.msdn.com/zowens/archive/tags/Spatial/default.aspx">Spatial</category><category domain="http://blogs.msdn.com/zowens/archive/tags/SSDS/default.aspx">SSDS</category><category domain="http://blogs.msdn.com/zowens/archive/tags/Sync+Framework/default.aspx">Sync Framework</category><category domain="http://blogs.msdn.com/zowens/archive/tags/EDM/default.aspx">EDM</category><category domain="http://blogs.msdn.com/zowens/archive/tags/TechEd/default.aspx">TechEd</category></item><item><title>TechEd 2008 Developers - Data Platform Keynote Demo Architecture</title><link>http://blogs.msdn.com/zowens/archive/2008/06/03/teched-2008-developers-data-platform-keynote-demo-architecture.aspx</link><pubDate>Tue, 03 Jun 2008 16:42:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8571514</guid><dc:creator>ZachSkylesOwens</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/zowens/comments/8571514.aspx</comments><wfw:commentRss>http://blogs.msdn.com/zowens/commentrss.aspx?PostID=8571514</wfw:commentRss><description>&lt;p&gt;&lt;em&gt;By &lt;/em&gt;&lt;a href="http://blogs.msdn.com/zowens" target="_blank"&gt;&lt;em&gt;Zach Skyles Owens&lt;/em&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;Just minutes ago at TechEd 2008 Developers in Orlando Dave Campbell, Technical Fellow, was on stage with Bill Gates doing the Data Platform demo which included a host of exciting Microsoft Technologies.&lt;/p&gt; &lt;ul&gt; &lt;li&gt;SQL Server 2008 - Supports any data  &lt;li&gt;SQL Server Data Services (SSDS) - Quickly provisioning for unpredictable scale  &lt;li&gt;Microsoft Sync Framework - Keeping all data synchronized&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Building this demo has been one of the most rewarding experiences in my career.&amp;nbsp; Everyone involved has put in 110%.&lt;/p&gt; &lt;p&gt;When we set out to build this demo we spent a lot of time making sure that the architecture was something that we have heard customers asking for.&amp;nbsp; Since SSDS is such a new piece of the Microsoft Data Platform going through this process was an interesting experience.&lt;/p&gt; &lt;p&gt;In this article I will quickly highlight the architecture of this application and describe why we made some of the architecture decisions.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Scenario&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;This application was built around a fictitious company called Trey Research.&amp;nbsp; Trey Research is a news agency that has launched a new strategy aimed at turning bloggers into paid journalists by paying them for their articles and photos.&amp;nbsp; Bloggers from around the world submit articles and images through either a web application or Windows Mobile app.&amp;nbsp; New analysts at Trey Research find the best articles and images for a given geographic area of interest, combine them into a story and sell them to companies like MSNBC; paying the content creators in the process. &lt;/p&gt; &lt;p&gt;&lt;strong&gt;Architecture&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Here is a high-level overview of the architecture.&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/zowens/WindowsLiveWriter/58051fc9fbd3_713D/image_6.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="345" alt="image" src="http://blogs.msdn.com/blogfiles/zowens/WindowsLiveWriter/58051fc9fbd3_713D/image_thumb_2.png" width="772" border="0"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;SQL Server 2008 and WPF&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/zowens/WindowsLiveWriter/58051fc9fbd3_713D/image_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="160" alt="image" src="http://blogs.msdn.com/blogfiles/zowens/WindowsLiveWriter/58051fc9fbd3_713D/image_thumb.png" width="249" align="right" border="0"&gt;&lt;/a&gt;So starting from the News Analyst WPF App and SQL Server 2008.&amp;nbsp; We chose to use local SQL Server database connected to a WPF desktop application for a number of reasons including.&lt;/p&gt; &lt;ul&gt; &lt;li&gt;High Performance of a Local Database  &lt;li&gt;Powerful Analytics of the SQL Server platform  &lt;li&gt;Ability to execute Spatial Queries to search for relevant content  &lt;li&gt;Storage of all content types including geo-tagged text and images&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;News Analysts at Trey Research can search for content with a power UI including Spatial and Time based queries.&amp;nbsp; SQL Server uses powerful analytics on the back end to determine the target demographic for the content.&amp;nbsp; Some of the exciting technologies being used are:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;FILESTREAM to store binary data  &lt;li&gt;New DateTimeOffset type used to store the date and time a photo was taken, which preserves time zone information  &lt;li&gt;Spatial queries and indexes which allow for the fast retrieval of geo-tagged data.  &lt;li&gt;SQL Server Reporting Services to provide rich visualization of analytical data.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;strong&gt;SQL Server Data Services, Web Application and Mobile Device&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/zowens/WindowsLiveWriter/58051fc9fbd3_713D/image3.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="150" alt="image" src="http://blogs.msdn.com/blogfiles/zowens/WindowsLiveWriter/58051fc9fbd3_713D/image3_thumb.png" width="244" align="right" border="0"&gt;&lt;/a&gt;All of this content is submitted via a web site or via a Windows Mobile application.&amp;nbsp; The content submitted via the web site or mobile app are stored in SSDS.&amp;nbsp; Their core competency is managing news content, not building Internet scale data centers.&amp;nbsp; Trey Research decided to use SSDS as the data storage platform for a number of reasons:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;To quickly provision for the unpredictable scale of what is turning out to be a very popular web site  &lt;li&gt;The nature of news is that a large event can produce huge spikes in traffic, so they are relying on Microsoft's global infrastructure and Service Level Agreements  &lt;li&gt;SSDS is acting as a Data Hub where web and mobile devices submit content&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;strong&gt;Microsoft Sync Framework&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;The final piece of magic in this application is the Microsoft Sync Framework.&amp;nbsp; Sync is used to pull data down from SSDS into the local SQL Server database in addition to moving data from the mobile device into SSDS.&amp;nbsp; The sync framework provides a powerful platform for dealing with things like conflict detection, etc.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;As you can see there were a number of architecture decisions that had to be made.&amp;nbsp; Trey Research is using many of the powerful features of the Microsoft Data Platform to quickly build this application.&amp;nbsp; I'll continue to post information about this demo.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8571514" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/zowens/archive/tags/Business+Intelligence/default.aspx">Business Intelligence</category><category domain="http://blogs.msdn.com/zowens/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://blogs.msdn.com/zowens/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/zowens/archive/tags/FILESTREAM/default.aspx">FILESTREAM</category><category domain="http://blogs.msdn.com/zowens/archive/tags/Spatial/default.aspx">Spatial</category><category domain="http://blogs.msdn.com/zowens/archive/tags/SSDS/default.aspx">SSDS</category><category domain="http://blogs.msdn.com/zowens/archive/tags/Sync+Framework/default.aspx">Sync Framework</category><category domain="http://blogs.msdn.com/zowens/archive/tags/EDM/default.aspx">EDM</category><category domain="http://blogs.msdn.com/zowens/archive/tags/TechEd/default.aspx">TechEd</category></item><item><title>To FILESTREAM or not to FILESTREAM... That is the question.</title><link>http://blogs.msdn.com/zowens/archive/2008/03/03/to-filestream-or-not-to-filestream-that-is-the-question.aspx</link><pubDate>Tue, 04 Mar 2008 09:13:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8020290</guid><dc:creator>ZachSkylesOwens</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/zowens/comments/8020290.aspx</comments><wfw:commentRss>http://blogs.msdn.com/zowens/commentrss.aspx?PostID=8020290</wfw:commentRss><description>&lt;p&gt;Roger and I have been delivering a demo which highlights Spatial and FILESTREAM features of SQL Server 2008.&amp;nbsp; One of the common things we've heard from developers is...&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;em&gt;For years we've been told that large binary files should never be stored in the database...&amp;nbsp; Are you telling us to start storing these files in the database now?&amp;nbsp; If so, why?&amp;nbsp; Are we just supposed to throw this best practice out the window?&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;This is really a great question which has prompted some interesting discussions.&amp;nbsp; Obviously the answer is not black and white. So let's start by looking at what has changed.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;SQL Server 2008 is now a very powerful engine for storing binary files.&amp;nbsp; &lt;/strong&gt;&lt;/p&gt; &lt;ul&gt; &lt;li&gt;These files can be accessed through high performance Win32 streaming API's in addition to T-SQL.  &lt;li&gt;These files are managed by SQL Server in their own file groups which can be backed up restored along with the rest of your SQL Server data.&amp;nbsp; On the flip side you aren't required to backup and restore these file groups.  &lt;li&gt;Reading and writing these files can now be part of a database transaction.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;So you might be thinking to yourself...&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;em&gt;Sounds great!!!&amp;nbsp; Let's start storing all of our binary data in SQL Server.&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Well, there are some considerations to be made before signing up to rewrite your app to take advantage of FILESTREAM.&amp;nbsp; Here are some of the main considerations.&lt;/p&gt; &lt;p&gt;&lt;u&gt;Do other applications need direct access to your binary files?&lt;/u&gt;&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;If you read my &lt;a href="http://blogs.msdn.com/zowens/archive/2008/03/03/sql-server-2008-filestream-and-wpf-mediaelement-part-2-writing-filestream-data.aspx" target="_blank"&gt;article about writing files to FILESTREAM&lt;/a&gt; you probably noticed that you have to go through SQL Server to access the data in FILESTREAM.&amp;nbsp; There is no concept of &lt;br&gt;OpenFile("C:\Path_To_My_File\File_Name.docx")&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;&lt;u&gt;Does your architecture require database mirroring?&lt;/u&gt;&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;Database mirroring does not yet support FILESTREAM.&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Those are just a couple of the things to think about.&amp;nbsp; I'd recommend checking out &lt;a href="http://codeplex.com/SQLSrvE2E" target="_blank"&gt;our FILESTREAM sample on CodePlex&lt;/a&gt; and make some decisions for yourself.&amp;nbsp; &lt;/p&gt; &lt;p&gt;FILESTREAM is a great technology and we are really excited to see how developers incorporate it into their applications.&amp;nbsp; Feel free to post comments here about your experience integrating FILESTREAM into your architecture.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8020290" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/zowens/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://blogs.msdn.com/zowens/archive/tags/FILESTREAM/default.aspx">FILESTREAM</category></item><item><title>SQL Server 2008 FILESTREAM and WPF MediaElement - Part 2 (Writing FILESTREAM Data)</title><link>http://blogs.msdn.com/zowens/archive/2008/03/03/sql-server-2008-filestream-and-wpf-mediaelement-part-2-writing-filestream-data.aspx</link><pubDate>Tue, 04 Mar 2008 09:00:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8020160</guid><dc:creator>ZachSkylesOwens</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/zowens/comments/8020160.aspx</comments><wfw:commentRss>http://blogs.msdn.com/zowens/commentrss.aspx?PostID=8020160</wfw:commentRss><description>&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/zowens/WindowsLiveWriter/SQLServer2008FILESTREAMandWPFMediaElemen_12F84/codeplex-logo_2.jpg"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="92" alt="codeplex-logo" src="http://blogs.msdn.com/blogfiles/zowens/WindowsLiveWriter/SQLServer2008FILESTREAMandWPFMediaElemen_12F84/codeplex-logo_thumb.jpg" width="235" align="right" border="0"&gt;&lt;/a&gt; Wow...&amp;nbsp; It's been a long time coming.&amp;nbsp; I promised that I would explain in more detail how to write FILESTREAM data to SQL Server 2008.&amp;nbsp; This is the &lt;a href="http://blogs.msdn.com/zowens/archive/2007/10/11/sql-server-2008-filestream-and-wpf-mediaelement.aspx" target="_blank"&gt;second article in a series&lt;/a&gt; and uses the sample published on the &lt;a href="http://codeplex.com/SQLSrvE2E" target="_blank"&gt;SQL Server Community Samples site on CodePlex&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;Writing data to a varbinary(max) FILESTREAM column in SQL is a bit more involved then just opening a file on the filesystem.&amp;nbsp; SQL Server needs to manage this operation within a transaction which adds a bit of complexity.&amp;nbsp; Here are the basic steps...&amp;nbsp; These steps apply both to reading and writing.&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Start a SQL Server transaction&lt;/li&gt; &lt;li&gt;Insert a row into the table containing metadata&lt;/li&gt; &lt;li&gt;Select the PathName from SQL Server which will be used to get a handle&lt;/li&gt; &lt;li&gt;Open a handle for writing using sqlncli10.dll&lt;/li&gt; &lt;li&gt;Use that handle within System.IO classes&lt;/li&gt; &lt;li&gt;Commit the transaction&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;Now that the basic steps are laid out, let's take a closer look.&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="color: green"&gt;// Start up a database transaction.
&lt;/span&gt;&lt;span style="color: #2b91af"&gt;SqlTransaction &lt;/span&gt;txn = cxn.BeginTransaction();&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;No need for explanation there.&lt;/p&gt;&lt;/blockquote&gt;&lt;pre class="code"&gt;&lt;span style="color: green"&gt;// Insert a row into the table to create a handle for streaming write.
&lt;/span&gt;&lt;span style="color: #2b91af"&gt;SqlCommand &lt;/span&gt;cmd = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;SqlCommand&lt;/span&gt;(&lt;span style="color: #a31515"&gt;"INSERT [dbo].[media]([mediaId], [fileName], &lt;br&gt;        [contentType]) VALUES( @mediaId, @fileName, @contentType);"&lt;/span&gt;, cxn, txn);&lt;/pre&gt;
&lt;blockquote&gt;
&lt;p&gt;This is worth a bit talking about.&amp;nbsp; Why do you &lt;u&gt;need&lt;/u&gt; to insert a row with metadata?&amp;nbsp; The answer is that in order to get a handle to the FILESTREAM column the row cannot have a NULL value in the FILESTREAM column.&amp;nbsp; This took some trial and error to discover.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;If you look closely at the create table script in the sample code you will see that the varbinary(max) FILESTREAM column default is set to a zero byte binary value.&lt;/p&gt;&lt;pre class="code"&gt;file varbinary(max) FILESTREAM &lt;span style="color: blue"&gt;DEFAULT&lt;/span&gt;(&lt;span style="color: blue"&gt;0x&lt;/span&gt;)&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;p&gt;This should make a bit more sense once we look at the next step.&lt;/p&gt;&lt;/blockquote&gt;&lt;pre class="code"&gt;&lt;span style="color: green"&gt;// Get a filestream PathName token and filestream transaction context.
// These items will be used to open up a file handle against the empty blob instance.
&lt;/span&gt;cmd = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;SqlCommand&lt;/span&gt;(&lt;span style="color: #a31515"&gt;"SELECT [file].PathName(), GET_FILESTREAM_TRANSACTION_CONTEXT() &lt;br&gt;        FROM [dbo].[media] WHERE [mediaId] = @mediaId;"&lt;/span&gt;, cxn, txn);&lt;/pre&gt;&lt;pre class="code"&gt;...&lt;span style="color: green"&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre class="code"&gt;&lt;span style="color: green"&gt;// Read in results of file.PathName()
&lt;/span&gt;&lt;span style="color: #2b91af"&gt;SqlString &lt;/span&gt;sqlFilePath = rdr.GetSqlString(0);&lt;/pre&gt;&lt;font style="background-color: #f2f2f2" face="Courier New"&gt;&lt;/font&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;blockquote&gt;
&lt;p&gt;So...&amp;nbsp; Here's where I think things get interesting.&amp;nbsp; You can see that the SELECT statement above calls the PathName() method of the FILESTREAM column.&amp;nbsp; Here's an example of the results from the query above. &lt;em&gt;Note the use of UDTs and CLR!&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="1"&gt;\\ZOWENS-NB3\MSSQLSERVER\v1\FilestreamWpfHttp\dbo\media\file\4C3C9C2D-8268-43FF-8317-D507319FE21C&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;This is a "virtual" path managed by SQL Server.&amp;nbsp; It consists of \\COMPUTER_NAME, followed by a configurable handler \MSSQLSERVER...&lt;/p&gt;
&lt;p&gt;Now what?&lt;/p&gt;&lt;/blockquote&gt;&lt;pre class="code"&gt;&lt;span style="color: green"&gt;// Get a Win32 file handle to the empty blob instance using SQL Native Client call.
// This is required in order to write to the empty blob instance.
&lt;/span&gt;&lt;span style="color: #2b91af"&gt;SafeFileHandle &lt;/span&gt;handle = &lt;span style="color: #2b91af"&gt;SqlNativeClient&lt;/span&gt;.OpenSqlFilestream(
        sqlFilePath.Value, 
        &lt;span style="color: #2b91af"&gt;SqlNativeClient&lt;/span&gt;.DESIRED_ACCESS_WRITE, 
        0, 
        transactionToken.Value, 
        (&lt;span style="color: #2b91af"&gt;UInt32&lt;/span&gt;)transactionToken.Value.Length, 
        &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;SqlNativeClient&lt;/span&gt;.&lt;span style="color: #2b91af"&gt;LARGE_INTEGER_SQL&lt;/span&gt;(0));&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;blockquote&gt;
&lt;p&gt;The code above uses a simple C# class "SqlNativeClient" that wraps the sqlncli10.dll I mentioned above.&amp;nbsp; This C# class is key to working with FILESTREAM in managed code.&amp;nbsp; You can see that we passed in the sqlFilePath variable from the PathName() query.&lt;/p&gt;&lt;/blockquote&gt;&lt;pre class="code"&gt;&lt;span style="color: green"&gt;// Open up a new stream to write the file to the blob.
&lt;/span&gt;&lt;span style="color: #2b91af"&gt;System.IO.FileStream &lt;/span&gt;destBlob = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;System.IO.FileStream&lt;/span&gt;(handle, &lt;span style="color: #2b91af"&gt;FileAccess&lt;/span&gt;.Write);&lt;/pre&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;
&lt;blockquote dir="ltr" style="margin-right: 0px"&gt;
&lt;p&gt;"Old school" System.IO file manipulation using the handle obtained from the SqlNativeClient class above.&lt;/p&gt;&lt;/blockquote&gt;&lt;pre class="code"&gt;&lt;span style="color: green"&gt;// Commit transaction&lt;/span&gt;        
txn.Commit();&lt;/pre&gt;There you have it...&amp;nbsp; It's not rocket science but there are a few tricks.&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8020160" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/zowens/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://blogs.msdn.com/zowens/archive/tags/FILESTREAM/default.aspx">FILESTREAM</category></item><item><title>FILESTREAM Support in SQL Server Express</title><link>http://blogs.msdn.com/zowens/archive/2007/12/18/filestream-support-in-sql-server-express.aspx</link><pubDate>Tue, 18 Dec 2007 22:39:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6798971</guid><dc:creator>ZachSkylesOwens</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/zowens/comments/6798971.aspx</comments><wfw:commentRss>http://blogs.msdn.com/zowens/commentrss.aspx?PostID=6798971</wfw:commentRss><description>&lt;p&gt;A couple great questions came up last week when discussing FILESTREAM with some people within the Microsoft field which I thought were worth sharing.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;&lt;strong&gt;Q:&lt;/strong&gt; Will &lt;a href="http://www.microsoft.com/sql/editions/express/default.mspx" target="_blank"&gt;SQL Server 2008 Express edition&lt;/a&gt; support FILESTREAM?&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;&lt;strong&gt;A:&lt;/strong&gt; It sure will!&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Q:&lt;/strong&gt; Will the &lt;a href="http://www.microsoft.com/sql/editions/express/features.mspx" target="_blank"&gt;4GB limit of Express&lt;/a&gt; apply to data stored in the FILESTREAM?&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;A:&lt;/strong&gt; Nope...&amp;#160; Go ahead and store large binary files!&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;As you may have noticed I'm really excited about binary data becoming a first class citizen in SQL Server 2008.&amp;#160; Once you dig into it I think you will agree.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6798971" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/zowens/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://blogs.msdn.com/zowens/archive/tags/FILESTREAM/default.aspx">FILESTREAM</category></item><item><title>SQL Server 2008 FILESTREAM and WPF MediaElement - Part 1 (Architecture)</title><link>http://blogs.msdn.com/zowens/archive/2007/10/11/sql-server-2008-filestream-and-wpf-mediaelement.aspx</link><pubDate>Fri, 12 Oct 2007 01:52:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5407749</guid><dc:creator>ZachSkylesOwens</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/zowens/comments/5407749.aspx</comments><wfw:commentRss>http://blogs.msdn.com/zowens/commentrss.aspx?PostID=5407749</wfw:commentRss><description>&lt;p&gt;If you have been following progress on &lt;a href="http://www.microsoft.com/sql/2008/default.mspx" target="_blank"&gt;SQL Server 2008&lt;/a&gt; you have probably seen mention of FILESTREAM which is an enhancement of the varbinary(Max) data type.&amp;nbsp; As an application developer you might be asking yourself...&amp;nbsp; "So what does this mean to me?"&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/zowens/WindowsLiveWriter/SQLServer2008FileStreamandWPFMediaElemen_10955/image_8.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="193" alt="image" src="http://blogs.msdn.com/blogfiles/zowens/WindowsLiveWriter/SQLServer2008FileStreamandWPFMediaElemen_10955/image_thumb_3.png" width="193" align="left" border="0"&gt;&lt;/a&gt;My partner-in-crime Roger Doherty and I grabbed early builds of SQL Server 2008 (Katmai) CTP5 and Visual Studio 2008 (Orcas) from the source trees and fled to the East coast for the week &lt;a href="http://blogs.msdn.com/rdoherty/archive/2007/10/10/sql-server-2008-the-engine-that-powers-immersive-user-experiences.aspx" target="_blank"&gt;to develop a demo&lt;/a&gt; which FILESTREAM is an important part of.&amp;nbsp; We've had a great time working into the middle of the night making some interesting discoveries.&amp;nbsp; Roger is covering some of the database level lessons learned &lt;a href="http://blogs.msdn.com/rdoherty/archive/2007/10/12/getting-traction-with-sql-server-2008-filestream.aspx" target="_blank"&gt;over on his blog which I recommend you checkout&lt;/a&gt;.&amp;nbsp; &lt;/p&gt; &lt;p&gt;As Rog pointed out we are trying to highlight "SQL Server is the Engine that Powers Rich User Experiences".&amp;nbsp; What does that mean?&amp;nbsp; It means that SQL Server is not just a bit bucket.&amp;nbsp; It can be an integral part of high-impact applications built for the desktop and Web.&amp;nbsp; With the new FILESTREAM support SQL Server becomes a much more viable solution for storing rich media such as images and video.&amp;nbsp; &lt;/p&gt; &lt;p&gt;&lt;em&gt;&lt;strong&gt;Question: &lt;/strong&gt;Now that binary data is in the database how can I get to it and what can I do with it?&lt;/em&gt;&lt;/p&gt; &lt;p&gt;&lt;em&gt;&lt;strong&gt;Answer:&lt;/strong&gt; Use WPF's MediaElement to display it!&lt;/em&gt;&lt;/p&gt; &lt;p&gt;Well...&amp;nbsp; It's not quite that simple.&amp;nbsp; In order for SQL Server to maintain transaction consistency, etc. you have to use some of it's API's to get at the data stored in the FILESTREAM which I'll cover in more detail below.&lt;/p&gt; &lt;p&gt;&lt;a href="http://wpf.netfx3.com/" target="_blank"&gt;Windows Presentation Foundation (WPF)&lt;/a&gt; in conjunction with &lt;a href="http://msdn2.microsoft.com/en-us/vstudio/default.aspx" target="_blank"&gt;Visual Studio 2008&lt;/a&gt; and &lt;a href="http://www.microsoft.com/expression/products/overview.aspx?key=blend" target="_blank"&gt;Expression Blend&lt;/a&gt; is an amazing combo for developing desktop and web applications.&amp;nbsp; In WPF the &lt;a href="http://msdn2.microsoft.com/en-us/library/bb412387.aspx" target="_blank"&gt;MediaElement&lt;/a&gt; tag/object can be used to display images and videos.&amp;nbsp; MediaElement requires the Source URI to be set.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;XAML&lt;/strong&gt;&amp;nbsp; &lt;br&gt;&lt;span style="color: rgb(0,0,255)"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;mediaelement&lt;/span&gt;&lt;span style="color: rgb(255,0,0)"&gt; x&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;:&lt;/span&gt;&lt;span style="color: rgb(255,0,0)"&gt;name&lt;/span&gt;&lt;span style="color: rgb(0,0,255)"&gt;="MyMediaPlayer" /&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; &lt;p&gt;&lt;strong&gt;C#&lt;/strong&gt; &lt;br&gt;MyMediaPlayer.Source = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; System.&lt;span style="color: rgb(43,145,175)"&gt;Uri&lt;/span&gt;(&lt;span style="color: rgb(163,21,21)"&gt;"PATH_TO_MEDIA"&lt;/span&gt;);&lt;/p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; &lt;p&gt;&lt;/p&gt; &lt;p&gt;In the C# code above the "PATH_TO_MEDIA" needs to be a valid URI which is where things get tricky working with FILESTREAM.&amp;nbsp; Below are a few different options.&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Socket level application (working with bits == lots of control)  &lt;li&gt;Custom data source for &lt;a href="http://www.microsoft.com/windows/windowsmedia/forpros/server/server.aspx" target="_blank"&gt;Windows Media Services&lt;/a&gt; (very powerful)  &lt;li&gt;Extension to &lt;a href="http://www.iis.net/downloads/default.aspx?tabid=34&amp;amp;g=6&amp;amp;i=1522" target="_blank"&gt;IIS Media Pack&lt;/a&gt; (very cool and should be done)  &lt;li&gt;Web application (quick and easy) &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;There may be other options then the ones mentioned above but those are what come to mind.&amp;nbsp; They all have ups and downs including performance, control, accessibility.&amp;nbsp; Roger and I chose to write a ASP.NET application for the following reasons.&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Experience with webapps, so it was a comfortable choice  &lt;li&gt;Quick to implement  &lt;li&gt;It's probably a scenario that a lot of developers will try &lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/zowens/WindowsLiveWriter/SQLServer2008FileStreamandWPFMediaElemen_10955/image_6.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="242" alt="image" src="http://blogs.msdn.com/blogfiles/zowens/WindowsLiveWriter/SQLServer2008FileStreamandWPFMediaElemen_10955/image_thumb_2.png" width="492" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;A quick look at the diagram above highlights one of the tradeoffs of this architecture.&amp;nbsp; Every time a user requests a media file it must be sent through a web server via HTTP.&amp;nbsp; This could be a benefit if offering this application as a service.&amp;nbsp; It could be a performance bottleneck if the entire application runs locally.&amp;nbsp; &lt;/p&gt; &lt;p&gt;Now that we have laid the architectural foundation the following articles will go into more of the implementation details.&lt;/p&gt; &lt;p&gt;&lt;a href="http://blogs.msdn.com/zowens/archive/2008/03/03/sql-server-2008-filestream-and-wpf-mediaelement-part-2-writing-filestream-data.aspx" target="_blank"&gt;Part 2 (Writing FILESTREAM Data)&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=5407749" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/zowens/archive/tags/SQL+Server/default.aspx">SQL Server</category><category domain="http://blogs.msdn.com/zowens/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/zowens/archive/tags/Windows+Presentation+Framework/default.aspx">Windows Presentation Framework</category><category domain="http://blogs.msdn.com/zowens/archive/tags/FILESTREAM/default.aspx">FILESTREAM</category><category domain="http://blogs.msdn.com/zowens/archive/tags/MediaElement/default.aspx">MediaElement</category><category domain="http://blogs.msdn.com/zowens/archive/tags/Spatial/default.aspx">Spatial</category></item></channel></rss>