简体   繁体   English

使用连接字符串localhost \\ SQLEXPRESS的用户的C#登录失败

[英]C# Login Failed for User using Connection String localhost\SQLEXPRESS

I got error message when connecting my apps on client PC to the Database stored on Server PC(DESKTOP-F419755). 将客户端PC上的应用程序连接到服务器PC上存储的数据库(DESKTOP-F419755)时出现错误消息。 I've tried using "localhost\\SQLEXPRESS" and ".\\SQLEXPRESS" but i got the same "Login Failed for user admin ..." message when trying to open connection. 我尝试使用“ localhost \\ SQLEXPRESS”和“。\\ SQLEXPRESS”,但在尝试打开连接时收到相同的“用户admin登录失败...”消息。 BUT, when i use "DESKTOP-F419755\\SQLEXPRESS" for the Connection String it's works well on Client PC.. 但是,当我使用“ DESKTOP-F419755 \\ SQLEXPRESS”作为连接字符串时,它在客户端PC上运行良好。

So how Client PC can connect to Server PC's Database without telling the Server PC Name. 因此,客户端PC如何在不告知服务器PC名称的情况下连接到服务器PC的数据库。

My full Connection String was "Data Source=localhost\\SQLEXPRESS;Initial Catalog=data;User ID=admin;Password=adminPass" 我的完整连接字符串是“数据源= localhost \\ SQLEXPRESS;初始目录=数据;用户ID = admin;密码= adminPass”

note: I can use either "localhost\\SQLEXPRESS", ".\\SQLEXPRESS", and "DESKTOP-F419755\\SQLEXPRESS" on PC Server(Ofcourse). 注意:我可以在PC Server(Ofcourse)上使用“ localhost \\ SQLEXPRESS”,“。\\ SQLEXPRESS”和“ DESKTOP-F419755 \\ SQLEXPRESS”。

So how Client PC can connect to Server PC's Database without telling the Server PC Name 因此,客户端PC如何在不告知服务器PC名称的情况下连接到服务器PC的数据库。

I am assuming you want to somehow mask the identity of the host in the configuration file for whatever reason. 我假设您出于某种原因想要以某种方式屏蔽配置文件中主机的身份。 You can use the IP address directly in the connection string or add a host entry in the file: C:\\Windows\\System32\\Drivers\\etc\\hosts 您可以直接在连接字符串中使用IP地址,也可以在文件中添加主机条目:C:\\ Windows \\ System32 \\ Drivers \\ etc \\ hosts

DESKTOP-F419755 serverhost DESKTOP-F419755服务器主机

And use: 并使用:

Data Source=serverhost\\SQLEXPRESS;Initial Catalog=data;User ID=admin;Password=adminPass 数据源= serverhost \\ SQLEXPRESS;初始目录=数据;用户ID = admin;密码= adminPass

Is the configuration file exposed to users? 配置文件是否向用户公开? What are you trying to accomplish exactly? 您到底想完成什么?

If your goal is to simply hide the machine name, this will accomplish albeit relatively half heatedly. 如果您的目标是简单地隐藏计算机名称,尽管可以完成一半的工作,但仍可以完成。 If your primary concern is security you can pull the host name from somewhere inside the code and in the code generate the connection object therefore not needing the connection string stored in the config file. 如果您最关心的是安全性,则可以从代码内部的某个位置提取主机名,然后在代码中生成连接对象,因此不需要存储在配置文件中的连接字符串。

This all depends on what you're trying to accomplish here, you could encrypt the information in the configuration file as well or store the host name somewhere else completely (registry, etc). 所有这些都取决于您要在此处完成的工作,您也可以对配置文件中的信息进行加密,或者将主机名完全存储在其他位置(注册表等)。

it's not possible to automate the connection string inside a client server location. 您无法在客户端服务器位置自动执行连接字符串。 however you can use another ways to store connection information to change without reinstalling the application. 但是,您可以使用其他方法来存储要更改的连接信息,而无需重新安装该应用程序。

  1. Use a text file in a location with connection string. 在带有连接字符串的位置中使用文本文件。 ensure that information are encrypted for security purposes. 确保出于安全目的对信息进行加密。

Hope you got the answer. 希望你得到答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM