• Hello and welcome to our new forums. We upgraded our forum sites to a more robust and modern system which we hope you will enjoy. Be sure to check out your profile by clicking the button on the top right and configure your preferences, signature, time zone, avatar, etc. as you wish. If you need help with using this new forum'ware try the help link on the bottom right.

    Click here to review your account now.

Running C# Database application for multiple clients

lional

Active member
Joined
Nov 29, 2018
Messages
25
Programming Experience
Beginner
Hi

I have a database application written in C# for a theological college. If I want to use the same application for another college at a different site with another database, what is the best way to connect to the database.

I currently use a connection string but that means changing the string for each college.

Is there a way to have a generic connection method? Is the best to use odbc to connect to the database or is there a better method.

I am trying to make the application portable without having to make changes for each college.

Just point me in the right direction, I don't believe in being given the code, it is not the way to learn.

Thank you, much appreciated.
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
2,202
Location
Sydney, Australia
Programming Experience
10+
If the database is not at the same location in each case then you have no choice but to change the connection string. If, for instance, a database will be created on a server at each site and that server may have a different name each time then you have to provide that name each time. You could use ODBC and specify a DSN, but then you need to save a new DSN on each machine with the connection details, so you just push the issue back one step. The only way that helps is if each machine already has a DSN for that server and you can then specify the database after connecting. If your database is local to the application then you wouldn;t have that same issue, because you can use the "|DataDirectory|" placeholder in your connection string and it will be resolved at run time. The other option is to build the connection string at run time from values provided by the user and saved locally, perhaps using application settings.
 

Sagar-Jaybhay

Member
Joined
Feb 19, 2019
Messages
8
Location
Pune
Programming Experience
5-10
Facebook
sagar.jaybhay.906
Twitter
sagar_jaybhay
You can create one table where you can put mapping of your database string along with your identification id. At the time of running application read value from that table.
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
2,202
Location
Sydney, Australia
Programming Experience
10+
You can create one table where you can put mapping of your database string along with your identification id. At the time of running application read value from that table.
That would require you to have one master database that every user at every site connected to first to then get the connection details for their own database. It would also mean that you'd still have to edit the site ID after deployment, so why not just edit the connection string?
 

Skydiver

Well-known member
Joined
Apr 6, 2019
Messages
50
Location
Virginia Beach, VA
Programming Experience
10+
Personally, I'm kind of worried that you have 3 different organizations sharing a single database. I hope that database is not sitting naked on the Internet. Recall the recent (NoSQL ?) database breaches where some people had left databases exposed naked on the Internet -- and even worse they left the default sign in accounts active.
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
2,202
Location
Sydney, Australia
Programming Experience
10+
Personally, I'm kind of worried that you have 3 different organizations sharing a single database.
As far as I can tell, that's not the case. If it was, there'd be no need for the question because everyone would be using the same known connection details. From my reading, this application will be used at multiple sites and each site will have their own copy of the database in their own choice of location, which is why the connection details need to be different for each site. The very first paragraph of the question says "another database" so that kinda rules out a "single database".
 
Top Bottom