我有启用了文件流的数据库
我能够写入数据库,但是当我尝试读回数据时,出现此错误
System.Data.dll中发生类型为'System.ComponentModel.Win32Exception'的未处理的异常其他信息:用户名或密码不正确
我正在尝试执行的代码是这样的
public void ReadFromDatabase()
{
using (SqlConnection connection = new SqlConnection(sql_ConnectionString))
{
connection.Open();
SqlCommand cmd = new SqlCommand("SELECT TOP(1) Video.PathName(), GET_FILESTREAM_TRANSACTION_CONTEXT() FROM Library", connection);
SqlTransaction sqlTrans = connection.BeginTransaction(IsolationLevel.ReadCommitted);
cmd.Transaction = sqlTrans;
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
string path = reader.GetString(0);
byte[] transContext = reader.GetSqlBytes(1).Buffer;
using (Stream fileStream = new SqlFileStream(path, transContext, FileAccess.Read, FileOptions.SequentialScan, allocationSize: 0))
{
byte[] data = new byte[fileStream.Length];
fileStream.Read(data, 0, (int)fileStream.Length);
File.WriteAllBytes(@"C:\Users\Georgi\AppData\Local\VideoPresenter\temp.mp4", data);
}
}
}
}
}
我使用的是集成安全性,因此用户名和密码保持不变,并已硬编码到应用程序中。
这是连接字符串代码
//Create a string builder object
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
//Set the properties of the builder
builder.AsynchronousProcessing = false;
builder.DataSource = "xxx.xxx.xxx.xxx";
builder.IntegratedSecurity = true;
builder.InitialCatalog = "VideoLibrary";
//Set the connection string and connection objects' data
sql_ConnectionString = builder.ToString();
//try to connect to the server
然后我只用字符串打开连接
传递的连接字符串为
“数据源= xxx.xxx.xxx.xxx;初始目录= VideoLibrary;集成安全性= True”
这是堆栈跟踪
System.Data.dll!System.Data.SqlTypes.SqlFileStream.OpenSqlFileStream(string path, byte[] transactionContext, System.IO.FileAccess access, System.IO.FileOptions options, long allocationSize) Unknown
System.Data.dll!System.Data.SqlTypes.SqlFileStream.SqlFileStream(string path, byte[] transactionContext, System.IO.FileAccess access, System.IO.FileOptions options, long allocationSize) Unknown
SQL FILESTREAM测试CLIENT.exe!SQL_FILESTREAM_TEST_CLIENT.SQLOperations.ReadFromDatabase()第158行C#SQL FILESTREAM测试CLIENT.exe!SQL_FILESTREAM_TEST_CLIENT.MainWindow.GetButton_Click(对象发送方,System.Windows.RoutedEventArgs eCore)第47 C行。 .RoutedEventHandlerInfo.InvokeHandler(对象目标,System.Windows.RoutedEventArgs routedEventArgs)未知PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(对象源,System.Windows.RoutedEventArgs args,bool reRaised)未知PresentationCore.dll!System.Windows。 UIElement.RaiseEventImpl(System.Windows.DependencyObject sender,System.Windows.RoutedEventArgs args)未知PresentationCore.dll!System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs e)未知PresentationFramework.dll!System.Windows.Controls.Primitives .ButtonBase。OnClick()未知PresentationFramework.dll!System.Windows.Controls.Button.OnClick()未知PresentationFramework.dll!System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(System.Windows.Input.MouseButtonEventArgs e)未知PresentationCore.dll! System.Windows.UIElement.OnMouseLeftButtonUpThunk(对象发送者,System.Windows.Input.MouseButtonEventArgs e)未知PresentationCore.dll!System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate genericHandler,对象genericTarget)未知PresentationCore.dll!系统。 Windows.RoutedEventArgs.InvokeHandler(System.Delegate处理程序,对象目标)Unknown PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(对象目标,System.Windows.RoutedEventArgs routedEventArgs)未知PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(对象源System.Windows.RoutedEventArgs参数,布尔值重新引发)未知PresentationCore.dll!System.Windows.UIElement.ReRaiseEventAs(System.Windows.DependencyObject发送者,System.Windows.RoutedEventArgs参数,System.Windows.RoutedEvent newEvent)未知PresentationCore.dll!系统.Windows.UIElement.OnMouseUpThunk(对象发送方,System.Windows.Input.MouseButtonEventArgs e)未知PresentationCore.dll!System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate genericHandler,对象genericTarget)未知PresentationCore.dll!System.Windows .RoutedEventArgs.InvokeHandler(System.Delegate处理程序,对象目标)Unknown PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(对象目标,System.Windows.RoutedEventArgs routedEventArgs)未知PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(对象来源,System.Windows.RoutedEventArgs参数,布尔值重新引发)未知PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject发送者,System.Windows.RoutedEventArgs args)未知PresentationCore.dll!System.Windows.UIElement.RaiseTrustedEvent( System.Windows.RoutedEventArgs args)未知PresentationCore.dll!System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs args,布尔受信任)Unknown PresentationCore.dll!System.Windows.Input.InputManager.ProcessStagingArea()未知PresentationCore.dll System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs输入)未知PresentationCore.dll!System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport inputReport)未知PresentationCore.dll!系统.Windows.Interop.HwndMouseInputProvider.ReportInput(System.IntPtr hwnd,System.Windows.Input.InputMode模式,int时间戳,System.Windows.Input.RawMouseActions操作,int x,int y,int wheel)未知PresentationCore.dll!System.Windows.Interop.HwndMouseInputProvider.FilterMessage(System.IntPtr hwnd, MS.Internal.Interop.WindowMessage msg,System.IntPtr wParam,System.IntPtr lParam,ref bool处理)未知PresentationCore.dll!System.Windows.Interop.HwndSource.InputFilterMessage(System.IntPtr hwnd,int msg,System.IntPtr wParam ,System.IntPtr lParam,ref bool处理)未知WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd,int msg,System.IntPtr wParam,System.IntPtr lParam,ref bool处理)未知WindowsBase.dll! MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o)未知WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate回调,对象args,int numArgs)未知的WindowsBase.dll!MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(对象源,System.Delegate方法,对象args,int numArgs,System.Delegate catchHandler)未知的WindowsBase.dll!System.Windows.Threading.Dispatcher。 LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority优先级,System.TimeSpan超时,System.Delegate方法,对象args,int numArgs)未知WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd,int msg,系统。 IntPtr wParam,System.IntPtr lParam)未知[本地到托管过渡]DispatcherPriority优先级,System.TimeSpan超时,System.Delegate方法,对象args,int numArgs)未知WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd,int msg,System.IntPtr wParam,System.IntPtr lParam)未知[本地到托管过渡]DispatcherPriority优先级,System.TimeSpan超时,System.Delegate方法,对象args,int numArgs)未知WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd,int msg,System.IntPtr wParam,System.IntPtr lParam)未知[本地到托管过渡]
[托管到本机过渡]
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame)未知WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading。 DispatcherFrame框架)未知WindowsBase.dll!System.Windows.Threading.Dispatcher.Run()未知PresentationFramework.dll!System.Windows.Application.RunDispatcher(对象忽略)未知PresentationFramework.dll!System.Windows.Application.RunInternal(系统。 Windows.Window窗口)未知PresentationFramework.dll!System.Windows.Application.Run(System.Windows.Window窗口)未知PresentationFramework.dll!System.Windows.Application.Run()未知SQL FILESTREAM测试CLIENT.exe!SQL_FILESTREAM_TEST_CLIENT.App .Main()C#[本地到托管过渡]
mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile,System.Security.Policy.Evidence assemblySecurity,string [] args)未知Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()未知mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(对象状态)未知mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext执行上下文,System.Threading.ContextCallback回调,对象状态,布尔状态,保持状态,同步Synctt) .dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext执行上下文,System.Threading.ContextCallback回调,对象状态,布尔类型saveSyncCtx)未知mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext执行上下文,System.Threading。ContextCallback回调,对象状态)未知mscorlib.dll!System.Threading.ThreadHelper.ThreadStart()未知
当打开Management Studio时,我看到填充了数据的行,但是无法从应用程序中读取数据
注意:只有默认的SQL Server用户“ sa”。我也尝试过使用它,但是结果是一样的。我用Windows用户创建数据库,而不用“ sa”数据库创建
注意:如果我要在连接字符串中使用DataSource =(local)运行代码,则它可以正常工作。
注意:数据库处于READ_WRITE模式
我试过的
我尝试重新创建表和整个数据库
我尝试重新安装SQL Server Express
我尝试向Windows添加功能,尤其是Internet信息服务->万维网服务->安全-> Windows身份验证/基本身份验证
我尝试操纵我正在使用的用户的权限,但这是一个dbo,所以应该没有问题。
我尝试在不同的计算机(使用相同的Microsoft帐户)上运行相同的代码*
我尝试设置尝试设置FILESTREAM(NON_TRANSACTED_ACCESS = FULL)
**我知道FileStream仅与Windows身份验证一起使用,并且我使用的是Windows 8,因此就帐户而言,一切都相同(或至少应该如此)**我是否缺少某些内容?
如果我要在连接字符串中使用DataSource =(local)运行代码,那么它将起作用。
因为这可行并且不能使用IP地址,所以我怀疑SQL Server将您的连接视为远程连接而不是本地连接。
打开“ SQL Server配置管理器”。选择“ SQL Server服务”。找到您正在使用的SQL Server实例,右键单击并选择“属性”。在“ FILESTREAM”选项卡上,选择“允许远程客户端访问FILESTREAM数据”。
如果我是正确的,那将解决您的问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句