0
votes

I got error message when connecting my apps on client PC to the Database stored on Server 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. BUT, when i use "DESKTOP-F419755\SQLEXPRESS" for the Connection String it's works well on Client PC..

So how Client PC can connect to Server PC's Database without telling the Server PC Name.

My full Connection String was "Data Source=localhost\SQLEXPRESS;Initial Catalog=data;User ID=admin;Password=adminPass"

note: I can use either "localhost\SQLEXPRESS", ".\SQLEXPRESS", and "DESKTOP-F419755\SQLEXPRESS" on PC Server(Ofcourse).

2
Do you mean connect on LAN ? - Kaj
Did you have a question? Is it buried in there somewhere? You said at one point it doesn't connect then you said it does connect. What is it that you having a hard time with? - Sean Lange
IT is telling you that the login failed for the user admin. Is there an admin user and is sql server in mixed mode? If you are not in mixed mode (The sql express default is windows auth only) than you cannot use the admin user. You also say that you are trying to connect over the network to another PC. Make sure the SQL server ports are open on the target machine and use the syntax {MACHINENAME}\SQLXPRESS - bhmahler

2 Answers

0
votes

So how Client PC can connect to Server PC's Database without telling the Server PC Name

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

DESKTOP-F419755 serverhost

And use:

Data Source=serverhost\SQLEXPRESS;Initial Catalog=data;User ID=admin;Password=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).

0
votes

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.