Click here to Skip to main content
15,884,353 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi.. i'm a degree student an i'm working on my final year project. its an app that connects to a remote server in order to manage a certain microsoft sql database created on that server. So i have completed all the functionality for this app except for the part where it connects to the database\server. And what i want is for the user to be able to specify, in the setting menu of this app, the ip address of the server to which they want to connect. And then login to the database using their login credentials. i've searched all over but keep seeing videos where the developer connects to the database through visual studio but i want the user of my app to have control in specifying the server to which they want to connect since the machine hosting the database may change in future. Please i need some guidelines on how to go about this. i'm using c# and wpf for this project. thanks

What I have tried:

connecting to the database using visual studio
Posted
Updated 14-Aug-17 11:02am

1 solution

OK, so your connection string needs to be modified in code. That's simple string manipulation.

The easiest way to do it is to just replace a tag in the string with the IP address or host name:
    Server={SERVER};Database=myDataBase;User Id=myUsername;
Password=myPassword;

C#
string ipAddress = "192.168.0.1";   // or a resolvable host name
string connString = templateConnString.Replace("{SERVER}", ipAddress);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900