是否可以让两个 SQL Server 实例(一个 2008 R2 和另一个 2012)在同一台机器上运行并且都启用了文件流?
我试图在本地开发机器上设置它,我可以让服务运行。但是当我尝试从 2008 R2 实例读取文件流时,我得到一个ArgumentException
.
两种情况下的路径看起来都不错。
SQL 服务器 2008 R2
\\DEVMC\MSSQLSERVER\v1\TESTDB\dbo\coreFileStore\fileData\525F2031-8D8C-45FF-8386-E1DD5F11C960
SQL Server 2012
\\DEVMC\EXPRESS2012\v1\TESTDB12\dbo\coreFileStore\fileData\525F2031-8D8C-45FF-8386-E1DD5F11C960
是否有任何神奇的设置可以使其在这两种情况下都有效,或者根本无法实现?
这是尝试使用 C# 测试代码访问文件时的异常堆栈跟踪。
System.ArgumentException : An invalid parameter was passed to the function.
at System.Data.SqlTypes.SqlFileStream.OpenSqlFileStream(String path, Byte[] transactionContext, FileAccess access, FileOptions options, Int64 allocationSize)
at System.Data.SqlTypes.SqlFileStream..ctor(String path, Byte[] transactionContext, FileAccess access, FileOptions options, Int64 allocationSize)
at System.Data.SqlTypes.SqlFileStream..ctor(String path, Byte[] transactionContext, FileAccess access)
at SimpleTests.FileStreamTest.ReadFilestream(String connectionstring, String fileid) in FileStreamTest.cs: line 47
这是我用来验证问题的 NUnit 测试方法。FileStore 访问 TESTDB 失败,但 TESTDB12 工作正常。
[TestCase(new object[] { "Data Source=localhost;Database=TESTDB;Integrated Security=True;Connect Timeout=120;", "525F2031-8D8C-45FF-8386-E1DD5F11C960" })]
[TestCase(new object[] { "Data Source=localhost\\express2012;Database=TESTDB12;Integrated Security=True;Connect Timeout=120;", "9AC28DC0-B927-4075-8D31-00E343E15663" })]
public void ReadFilestream(string connectionstring, string fileid)
{
const string _selectSql =
@"SELECT fileData.PathName(), GET_FILESTREAM_TRANSACTION_CONTEXT()
FROM coreFileStore
WHERE fileStoreId = @FileStoreId";
using (SqlConnection connection = new SqlConnection(connectionstring))
{
connection.Open();
using (SqlTransaction transaction = connection.BeginTransaction())
{
string filepath;
byte[] txnInfo;
using (SqlCommand command = connection.CreateCommand())
{
command.CommandText = _selectSql;
command.Parameters.AddWithValue("FileStoreId", new Guid(fileid));
command.Transaction = transaction;
using (SqlDataReader reader = command.ExecuteReader())
{
reader.Read();
filepath = reader.GetString(0);
txnInfo = reader.GetValue(1) as byte[];
}
}
Console.WriteLine(filepath);
using (SqlFileStream sqlFileStream = new SqlFileStream(filepath, txnInfo, FileAccess.Read))
{
using (StreamReader reader = new StreamReader(sqlFileStream))
{
string x = reader.ReadToEnd();
Console.WriteLine(x);
}
}
}
}
}