c# - C#应用程序访问数据库是否需要在PC上安装SQL客户端?

标签 c# wpf sql-server

我创建了一个 C3 WPF 应用程序来管理数据库上的数据。 到目前为止,我已经在 3 台独立的 PC 上成功使用了它,但在第四台 PC 上就崩溃了。异常(exception)是:

Faulting application name: LakeSmitFautLog.exe, version: 1.0.0.0, time stamp: 0x503b19ee
Faulting module name: KERNELBASE.dll, version: 6.1.7601.17651, time stamp: 0x4e2111c0
Exception code: 0xe0434352

Application: LakeSmitFautLog.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Data.SqlClient.SqlException
Stack:
   at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(System.Data.Common.DbConnection, System.Data.ProviderBase.DbConnectionFactory)
   at System.Data.SqlClient.SqlConnection.Open()
   at LakeSmitFautLog.MainWindow.LoadComboBoxes()
   at LakeSmitFautLog.MainWindow..ctor()
   at LakeSmitFautLog.initxaml.btnEnter_Click(System.Object, System.Windows.RoutedEventArgs)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object, System.Windows.RoutedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)
   at System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject, System.Windows.RoutedEventArgs)
   at System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs)
   at System.Windows.Controls.Primitives.ButtonBase.OnClick()
   at System.Windows.Controls.Button.OnClick()
   at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(System.Windows.Input.MouseButtonEventArgs)
   at System.Windows.UIElement.OnMouseLeftButtonUpThunk(System.Object, System.Windows.Input.MouseButtonEventArgs)
   at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate, System.Object)
   at System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate, System.Object)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object, System.Windows.RoutedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)
   at System.Windows.UIElement.ReRaiseEventAs(System.Windows.DependencyObject, System.Windows.RoutedEventArgs, System.Windows.RoutedEvent)
   at System.Windows.UIElement.OnMouseUpThunk(System.Object, System.Windows.Input.MouseButtonEventArgs)
   at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate, System.Object)
   at System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate, System.Object)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object, System.Windows.RoutedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)
   at System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject, System.Windows.RoutedEventArgs)
   at System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs)
   at System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs, Boolean)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs)
   at System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport)
   at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr, System.Windows.Input.InputMode, Int32, System.Windows.Input.RawMouseActions, Int32, Int32, Int32)
   at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr, MS.Internal.Interop.WindowMessage, IntPtr, IntPtr, Boolean ByRef)
   at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
   at System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)
   at System.Windows.Application.RunDispatcher(System.Object)
   at System.Windows.Application.RunInternal(System.Windows.Window)
   at System.Windows.Application.Run(System.Windows.Window)
   at LakeSmitFautLog.App.Main()

在前 3 台 PC 上,安装了独立的 MS SQL 客户端,但在提供错误的 PC 上未安装。
在应用程序中,我引用了 System.Data.SqlClient,但这似乎还不够。

如上标题,这第四台电脑是否需要安装独立的 SQL 客户端?

[编辑] 可能的解决方案需要禁用 SQL Server 的防火墙。问题可能在于它会将没有本地 IP 的人踢出(第四台 PC 来自不同的地点,具有不同的 IP 范围)。

最佳答案

简短的回答是

来自文档:

The .NET Framework Data Provider for SQL Server (SqlClient) uses its own protocol to communicate with SQL Server. It is lightweight and performs well because it is optimized to access a SQL Server directly without adding an OLE DB or Open Database Connectivity (ODBC) layer. The following illustration contrasts the .NET Framework Data Provider for SQL Server with the .NET Framework Data Provider for OLE DB. The .NET Framework Data Provider for OLE DB communicates to an OLE DB data source through both the OLE DB Service component, which provides connection pooling and transaction services, and the OLE DB provider for the data source.

Microsoft Sql Client Database Access

http://msdn.microsoft.com/en-us/library/a6cd7c08.aspx

那么……怎么了?

正如其他评论者所指出的,您对异常处理很轻;实际的异常似乎没有在任何地方被捕获。

鉴于您已经说过同一个 exe 正在另外 3 台计算机上运行,​​您确实需要实际的异常消息来确定它是否:

  1. 环境(可能机器无法连接数据库服务器)
  2. 基于用户(运行该程序的用户没有连接到数据库服务器的权限)
  3. 基于时间(当时服务器不可用,因此连接失败。)

如果您想发布 LoadComboBoxes 的代码(或者至少是数据库工作的代码),那么这可能会帮助我们提供一些进一步的建议。

关于c# - C#应用程序访问数据库是否需要在PC上安装SQL客户端?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12138588/

相关文章:

sql-server - 用于批量插入的触发触发器

c# - 如何使用 DirectShow NET 捕获音频和视频?

c# - 在 C# 中使用字符串调用哈希表

c# - 向前拉伸(stretch)我旋转的球员

c# - 如何处理 ResourceDictionary 中定义的 ControlTemplate 中的 EventHandlers?

.net - SQL Server CLR 函数

c# - 如何在 Entity Framework Core 中使用复数 DbSet 属性名称搭建 DbContext?

c# - BackgroundWorker.CancelAsync() 导致 "BackgroundWorker does not support cancellation."错误

wpf - 使用目标名称触发

服务中的 WPF FormattedText "The system cannot find the file specified"异常