如何在同一网络上制作wpf应用程序从一个SQL Server读取数据?

我在我的计算机上运行Visual Studio 2017中的C#WPF应用程序,我使用SQL Server 2014来保存/选择数据。

如何在不安装Visual Studio / SQL Server的情况下在同一网络上的另一台Windows计算机上运行它? 此应用程序应从/在我的SQL Server中读取/插入数据。

我尝试使用发布选项,但该应用程序无法从我的计算机上读取其他网络PC上的数据。

此外,我试图将bin复制到其他PC,但该应用程序仍然无法从SQL Server读取数据。

我已经准备SQL Server以使用以下链接上的以下步骤接收连接:

如何在与LAN连接的其他计算机上使用SQL Server数据库运行桌面应用程序

同样在app.config ,我找到了以下连接字符串:

  connectionString="Data Source=DESKTOP-QO2VUSP\SQLEXPRESS;Initial Catalog=AJFactory;Integrated Security=True" 

我检查了其他pc的事件处理程序,我发现以下错误:

应用程序:Factory App.exe Framework版本:v4.0.30319描述:由于未处理的exception,进程已终止。 exception信息:System.Data.SqlClient.SqlInternalConnectionTds..ctor中的System.Data.SqlClient.SqlException(System.Data.ProviderBase.DbConnectionPoolIdentity,System.Data.SqlClient.SqlConnectionString,System.Data.SqlClient.SqlCredential,System.Object, System.String,System.Security.SecureString,Boolean,System.Data.SqlClient.SqlConnectionString,System.Data.SqlClient.SessionData,System.Data.ProviderBase.DbConnectionPool,System.String,Boolean,System.Data.SqlClient.SqlAuthenticationProviderManager

以下内容:

错误应用程序名称:Factory App.exe,版本:1.0.0.0,时间戳:0x5bdb0efa错误模块名称:KERNELBASE.dll,版本:10.0.17134.319,时间戳:0x5ea0e53dexception代码:0xe0434352错误偏移量:0x001117d2

事实上它是一个WPF应用程序是无关紧要的。

您需要更改SqlConnection对象的连接字符串。 它可能会说“Data Source = Localhost”或“Data Source = 127.0.0.1”。 这应该更改为您的PC的网络名称。

您还需要检查您的Sql Server /数据库配置,其他用户具有此应用程序所需的正确访问权限。

请注意您拥有的连接字符串中的安全性类型:

 Integrated Security=True 

仅当两台计算机位于同一域中时才有效。 我建议你在connectionString中添加SQL的UserName和Password

您需要设置Integrated Security=False ,当为false时,需要在连接中指定User IDPassword有关Integrated Security的更多信息,请检查以下答案:

Integrated Security = True和Integrated Security = SSPI有什么区别?