FILESTREAM - 在 FILESTREAM 列中读写一个大文件
FILESTREAM - Read and write a large file in FILESTREAM column
我应该使用 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 服务器和应用程序安装在单独的服务器中时,我在设置 Windows 访问 SqlFileStream 文件路径的身份验证时遇到一些问题。我怎样才能避免这个问题?
我应该使用 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 服务器和应用程序安装在单独的服务器中时,我在设置 Windows 访问 SqlFileStream 文件路径的身份验证时遇到一些问题。我怎样才能避免这个问题?