[英]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 Server和應用程序安裝在單獨的服務器中時,我在設置Windows身份驗證以訪問SqlFileStream文件路徑時遇到一些問題。 我如何避免這個問題?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.