我应该使用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和Application安装在单独的服务器上时,我在设置Windows身份验证时遇到了一些问题,无法访问SqlFileStream文件路径。我怎么能避免这个问题?