Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Core support for SQL Server FILESTREAM

I'm in the process of upgrading an existing application to .NET Core (DNX SDK 1.0.0-rc1-update2) that uses SQL Servers FILESTREAM feature for reading/writing large BLOBs to the database. It uses the SqlFileStream class to achieve this however it doesn't appear to be available in .NET Core. Here are my references in project.json:

"frameworks": {
    "net451": {
      "frameworkAssemblies": {
        "System.Runtime": "4.0.10.0",
        "System.Collections": "4.0.0.0"
      }
    },
    "dotnet5.4": {
      "dependencies": {
        "Microsoft.CSharp": "4.0.1-beta-23516",
        "System.Data.Common": "4.0.1-beta-23516",
        "System.Data.SqlClient": "4.0.0-rc2-23623",
        "System.Collections": "4.0.11-beta-23516",
        "System.IO.FileSystem": "4.0.1-beta-23516",
        "System.Linq": "4.0.1-beta-23516",
        "System.Runtime": "4.0.21-beta-23516",
        "System.Threading": "4.0.11-beta-23516"
      }
    }
}

I've tried searching SO and Google, both of which have absolutely nothing on the subject.

Can someone please confirm if its actually unavailable or if its in another package I'm unaware of?

like image 590
lawst Avatar asked Apr 22 '16 11:04

lawst


People also ask

What is Filestream in SQL Server?

A FILESTREAM filegroup is a special filegroup that contains file system directories instead of the files themselves. These file system directories are called data containers. Data containers are the interface between Database Engine storage and file system storage.

What is the difference between Filestream and FileTable?

FileStream and FileTable are features of SQL Server for storing unstructured data in SQL Server alongside other data. The FileStream feature stores unstructured data in the file system and keeps a pointer of the data in the database, whereas FileTable extends this feature even further allowing non-transactional access.

Does Azure SQL support Filestream?

Filestream is not supported on Azure SQL Database, because of its nature PaaS. So, in case you do not want to change anything in your SQL Databases, you can consider to use Azure SQL Managed Instance.


2 Answers

I realize the question is old, but I just came across the issue - implementing SqlFileStream - listed on the github repo for CoreFX (.NET Core foundational libraries) and thought I'd mention it here. Here's a link to the issue, for reference: https://github.com/dotnet/corefx/issues/15652

To recap: The issue is implementing SqlFileStream. It's currently an open issue, but not on the horizon anytime soon. One of the contributors states "if there are any Windows specific dependencies, we may not bring it in Core."

like image 169
SWalters Avatar answered Sep 30 '22 16:09

SWalters


I've actually been interested in this for a while and have taken some time over the last few days.

Unfortunately, FILESTREAM uses several NTFS and NT specific system calls (NtCreateFile, DeviceIoControl in particular, but a few others to support those as well) to manage access to the file. Also, unfortunately, as of this writing the latest MSSQL CTPs for Linux don't support FILESTREAM, and there's little clarity as to whether that's on the roadmap or where it might be (strangely, you can restore a database that supports FILESTREAM but FileTable doesn't seem to be supported).

There are two problems here: it's not clear that replacing the NT specific APIs would respect transactional integrity (or even work at all), and it's not clear that they could ever work from a non-Windows environment anyway. Because of these facts, I don't see SqlFileStream being supported any time in the near future for core.

There is some precedent for Windows Only type of low level, for example in System.Net.Socket.IOControl. SqlFileStream could perhaps take a similar path. Alternatively, it might be possible to build a specific SqlFileStream NuGet package, but have it only be supported/runnable on Windows. I'm not sure how valuable this would be though - if you're going to P/Invoke in a Windows only way to begin with, why not just P/Invoke to a .NET 4.6.x dll?

Cross posting this to the github issue: https://github.com/dotnet/corefx/issues/15652

Edit: As an alternative to P/Invoke, you could certainly create some other kind of service (RESTful, WCF, some other pipe or TCP or even memory mapped file) in .NET 4.x for a .NET Core library or application to access.

like image 32
Dan Field Avatar answered Sep 30 '22 15:09

Dan Field