我一直试图弄清楚这个错误已经好几天了,我仍然不明白发生了什么
public async Task<int> UploadToDatabase_Data(VideoPresenterFile file, DatabaseConnectionObject connObj)
{
SqlConnectionStringBuilder WriteData_Builder = new SqlConnectionStringBuilder();
WriteData_Builder.InitialCatalog = connObj.Database;
WriteData_Builder.IntegratedSecurity = connObj.isIntegratedSecurityEnabled;
WriteData_Builder.DataSource = connObj.IP;
WriteData_Builder.AsynchronousProcessing = connObj.isAsyncEnabled;
using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
{
using (SqlConnection WriteData_Connection = new SqlConnection(WriteData_Builder.ToString()))
{
await WriteData_Connection.OpenAsync().ConfigureAwait(false);
SqlCommand WriteData_Command = new SqlCommand();
WriteData_Command.Connection = WriteData_Connection;
WriteData_Command.CommandText = "SELECT Video.PathName(), GET_FILESTREAM_TRANSACTION_CONTEXT() FROM VideoLibrary.dbo.Library WHERE Name = 'temp'";
//WriteData_Command.Parameters.Add("@NAME", SqlDbType.VarChar).Value = file.Name;
SqlTransaction WriteData_Transaction = WriteData_Connection.BeginTransaction("UploadDataTransaction");
WriteData_Command.Transaction = WriteData_Transaction;
using (SqlDataReader WriteData_TransactionReader = WriteData_Command.ExecuteReader())
{
await WriteData_TransactionReader.ReadAsync();
string WriteData_SqlPath = WriteData_TransactionReader.GetString(0);
byte[] WriteData_TransactionContext = WriteData_TransactionReader.GetSqlBytes(1).Value;
using (SqlFileStream WriteData_FileStream = new SqlFileStream(WriteData_SqlPath, WriteData_TransactionContext, FileAccess.Write))
{
int count = 20 * 1024 * 1024, offset = 0;
byte[] buffer = new byte[count];
FileInfo file_FileInfo = new FileInfo(file.Path);
FileStream file_FileStream = new FileStream(file_FileInfo.FullName, FileMode.Open, FileAccess.Read);
do
{
await file_FileStream.ReadAsync(buffer, offset, count);
await WriteData_FileStream.WriteAsync(buffer, offset, count);
offset += count;
} while (offset <= file_FileInfo.Length);
}
}
}
}
代码一直顺利执行到此行:
using (SqlFileStream WriteData_FileStream = new SqlFileStream(WriteData_SqlPath, WriteData_TransactionContext, FileAccess.Write))
然后出现错误。
错误: mscorlib.dll中发生了'System.ComponentModel.Win32Exception'类型的异常但未在用户代码中处理 附加信息:用户名或密码不正确 如果存在此异常的处理程序,则可以安全地继续该程序。
我可以添加插入一行,包含每个必要的细节。当我添加整行时,我不使用 TransactionScope 和 TransactionContext ,但当我尝试读取或写入特定于文件流的内容时,我正在使用范围和上下文,它会引发错误。
我尝试过:
我尝试重新创建表和整个数据库
我尝试重新安装SQL Server Express
我尝试向Windows添加功能,尤其是 Internet信息服务 - &gt;全球资讯网 服务 - &gt;安全 - &gt; Windows身份验证/基本身份验证
我尝试操纵我正在使用的用户的权限,但这是一个dbo,所以应该没有问题。
我尝试在不同的计算机上运行相同的代码(使用相同的Microsoft帐户)*
我知道FileStream仅适用于Windows身份验证,而我使用的是Windows 8,因此帐户方面的所有内容都相同(或至少应该是这样)