tags:

views:

94

answers:

2

I have come across this problem before and I have never understood the reasoning for it: in a desktop application developed in .Net the connection string is stored as a read-only value in the application's app config.

In every windows application I've written, the database needs to be set by the user: if I'm deploying an application to different sites it's unlikely they will be using the same database. Surely this is the common case for a desktop application? So why is the connection string made read-only in the framework?

Is it a case of the database framework designers thinking in terms of server applications and forgetting the desktop use-case?

+1  A: 

Nothing requires that you place your connection strings in app.config. You can use settings files (which are updateable and user-specific), the windows registry, or any datastore you want. In those cases where the database is not configurable, app.config just makes an easy place to define the connection.

What you SHOULD avoid is encoding the user's password in the connection string, unless you are using connection string encryption in your config file.

LBushkin
+2  A: 

Database connection info in an app.config for a desktop app sounds like a bad idea to me. Typically i would have a desktop app call to a web/wcf service, which in turn calls the DB (this way there is NO connection string stored on the client side)

It's probably a carry over from the way a lot of people do it on the server side. At least with Web apps, setting the connection string in the web.config file is a nice way to be able to change it without having to recompile.

If you want to allow the user to set thier own connection properties, a string in the app.config might be thought of as a DEFAULT setting.

Neil N
Why do you assume that every desktop app would always have access to some web service or WCF service? Many desktop apps are deployed in a stand-alone fashion and may connect to databases on the user's local machine. The strategy by which you acquire a connection string generally depends on the nature of the application itself.
LBushkin
@LBushkin, You can't run WCF locally? I didnt ASSUME anything, most of what I posted still applies even for a local DB. If the OP wants his users to select a DB (even if thier only choices are local ones) he STILL negates the need for a readonly setting, would he not?
Neil N
My point is that using web/wcf services as a mechanism to deliver settings or configuration to an application seems like overkill - particularly since there are alternative techniques that work just as well. And while you can certainly run web/wcf services locally you need to be able to justify the added complexity and fragility - since now you not only have to manage the configuration of the application, but also the configuration of the service.
LBushkin