2

If I could make the connection string a "User" setting for them to edit, that would do nicely for now. At the moment the string contains a reference to my machine, where my test DB sits. I want to build an alpha for somebody else to try, but they'll need to point it to their own DB instance.

More generally, what is the correct approach to keep DataSets in the Visual Studio designer whilst having a connection string capable of being pointed to the configured server by the user? - at the moment they seem dependant on the Connection String in my Settings.

Mario S
  • 11,715
  • 24
  • 39
  • 47
noelicus
  • 14,468
  • 3
  • 92
  • 111
  • Are you using Linq to Entities, LINQ to SQL, ADO or something else for connecting to the database? – nerdybeardo Oct 26 '12 at 13:07
  • It's an MS SQL db that I've created datasets for in my application using the Server Objects window, but also just using a SqlConnection call directly sometimes as it seems simpler. – noelicus Oct 26 '12 at 13:26

2 Answers2

0

Use app.config with System.Configuration, they can then set the correct connection string in the config.

See this question for how:

Get connection string from App.config

Community
  • 1
  • 1
mattmanser
  • 5,719
  • 3
  • 38
  • 50
  • Would you mind expanding on that a bit? The settings I'm referring to are accessed via `Properties.Settings.Default.etc` Visual Studio seems to keep these in an app.config file already ... are you saying that is copied somewhere that an administrator can edit the "application" values or some such? – noelicus Oct 26 '12 at 13:47
  • @noelicus Yes, that file will be necessary for the program to run if it contains anything. You can also edit the values in the program, although MS made it much harder to do so than it should be for no good reason. There are also embeddable properties that are saved inside the DLL, which is what I thought you were using because you asked this question. – mattmanser Oct 26 '12 at 14:04
  • So where does the app.config live, then? - the one administrators can edit. I can see the "users" one - its the application settings I'd like to edit if available. – noelicus Oct 26 '12 at 14:41
  • @noelicus Usually where ever the exe lives, it's in the root of solution if you've added it and would be in the root of obj/Release – mattmanser Oct 30 '12 at 09:18
0

Because, presumably, the ConnectionString back to your database contains highly sensitive information, such as server names, database names, even user ID's and passwords; as such, that information is inherently designed to be disguised or kept secret from the user community. Malevolent users of your application would very much enjoy the opportunity to leverage a user-controlled connection string.

It would seem that if you need to control data in this way, you should consider some kind of profiling mechanism that performs the specific data host selection in the background, not in an entirely user-controlled manner.

Edit

One possible alternative I would suggest is to determine the "alternative" servers in advance, and add the corresponding connection strings to the app's configuration file. In the application itself, provide some sort of user-friendly identifier that ties to the dataset the user wants to use, then tie that identifier behind the scenes to the proper connection string, thus keeping the particulars of the connection string private.

David W
  • 10,062
  • 34
  • 60