我应该使用System.Data.SqlTypes.SqlFileStream
读写FILESTREAM
列吗?
例如:
var sqlCommand = sqlConnection3.CreateCommand();
sqlCommand.CommandText = "Select FileData.PathName() As Path, GET_FILESTREAM_TRANSACTION_CONTEXT() As TransactionContext From PictureTable Where PkId = (Select Max(PkId) From PictureTable)";
var reader = sqlCommand.ExecuteReader();
reader.Read();
var filePath = (string)reader["Path"];
var transactionContext = (byte[])reader["TransactionContext"];
var sqlFileStream = new SqlFileStream(filePath, transactionContext, FileAccess.Read);
var data = new byte[sqlFileStream.Length];
sqlFileStream.Read(data, 0, Convert.ToInt16(sqlFileStream.Length));
在上面的代码中,我可以使用此处显示的查询并直接访问FileData
:
Select FileData From PictureTable Where PkId = (Select Max(PkId) From PictureTable)
如果不使用SqlFileStream
和使用varbinary(max)
来读写会发生什么?
当 SQL Server 和应用程序安装在单独的服务器中时,我在设置 Windows 身份验证以访问 SqlFileStream 文件路径时遇到了一些问题。我怎样才能避免这个问题?