我正在嘗試使用WCF服務中的SqlFileStream對象來獲取SQL Server 2012 FileTable中特定文件的句柄。我能夠得到的路徑和事務上下文,就像您使用這段代碼沒有問題,預計有:如何使用SqlFileStream來事務訪問SQL Server 2012 FileTable?
using (SqlConnection con2 = new SqlConnection(ConfigurationManager.ConnectionStrings["FileStorage"].ConnectionString))
{
con2.Open();
string getFileHandleQuery = String.Format(
@"SELECT FileTableRootPath(), file_stream.GetFileNamespacePath(), GET_FILESTREAM_TRANSACTION_CONTEXT()
FROM {0}
WHERE stream_id = @streamId", "FSStore");
byte[] serverTransactionContext;
string serverPath;
using (SqlCommand sqlCommand = new SqlCommand(getFileHandleQuery, con2))
{
sqlCommand.Parameters.Add("@streamId", SqlDbType.UniqueIdentifier).Value = new Guid(finalFileHandleStreamId);
using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader())
{
sqlDataReader.Read();
serverPath = String.Concat(sqlDataReader.GetSqlString(0).Value, sqlDataReader.GetSqlString(1).Value);
serverTransactionContext = sqlDataReader.GetSqlBinary(2).Value;
sqlDataReader.Close();
}
}
con2.Close();
}
但是,一旦我嘗試和實際使用的路徑和事務上下文來創建一個新SqlFileStream:
using (SqlFileStream dest =
new SqlFileStream(serverPath, serverTxn, FileAccess.Write))
{
...
}
上述情況除了以下例外:已裝入的文件系統不支持擴展屬性。
有人可以向我解釋我在這裏做錯了嗎?
謝謝!
您的代碼看起來不錯,但沒有更多的細節,它聽起來就像你可能有一個問題,您的設置在服務器端。如果你還沒有遇到這些問題,這些是設置你的服務器/數據庫使用sqlfilestream的兩個很好的來源。[link](https://www.simple-talk.com/sql/learn-sql-server/ an-introduction-to-sql-server-filestream /)和[link](http://lennilobel.wordpress.com/2011/08/22/using-sqlfilestream-in-c-to-access-sql-server- FILESTREAM數據/) – JMK 2013-12-06 04:15:31