Groups | Blog | Home
all groups > dotnet general > december 2006 >

dotnet general : Where to Store Database Connection String Info for Windows Forms Application



Merk
12/5/2006 11:28:12 PM
I'm looking for a safe and maintainable way to store connection string info
(connecting to SQL Server 2005 from .NET 2.0 Windows Forms client app);
things like server name or IP address and database name. I need to provide
the client application with this info for connecting to both a test SQL
Server and a production server.

I would prefer to NOT hard-code this info into the client application, and
App.Config seems rather unsafe as the users can change it with a text
editor.

What are my options?

Thanks.

RobinS
12/5/2006 11:54:58 PM
We store it in the Settings under the Project Properties. We're using
Windows security, so there are no usernames or passwords involved.

You could store two connectionstrings there (type = ConnectionString,
Scope = Application), then refer to them in your code as
My.Settings.ConnectionStringTest or something like that. (That's
what it's called in VB -- C# has different syntax.)

Robin S.
-------------------------------------
[quoted text, click to view]

RobinS
12/5/2006 11:55:51 PM
Of course, that puts it in app.config, which is where you
didn't want to put it. Sorry about that.

Robin S.
-------------------------
[quoted text, click to view]

Bruce Wood
12/6/2006 10:16:08 AM

[quoted text, click to view]

I've been looking into this same question in my spare time. One option
recommended by Microsoft is to store the connection string in
app.config, but to store it encrypted. Here is a good place to start
reading:

http://msdn2.microsoft.com/en-us/library/89211k9b.aspx

The difficulty is that all of the detailed articles I've found on
securing connection strings by encryption refer to Web applications,
not WinForms applications. There's probably a good reason for this:
encryption and decryption can work on a per-machine basis: one way you
can encrypt a string is to do so on a particular machine in such a way
that only that particular machine can decrypt it. That works great when
the only machine running your code is your IIS server. It doesn't work
at all well if you distribute your application to all and sundry.

I've yet to come across samples for a WinForms solution. Perhaps
there's a way to encrypt a string and store it in the configuration
file, then hard-code the secret portion of the key into one's
application. Hardly textbook security, but better than plaintext.
Merk
12/6/2006 11:36:02 AM
I appreciate your post. Perhaps a lazy-yet-effective way to go would be to
Base64 encode the string. That would "raise the bar enough" to satisfy my
desire to simply not have clear text in App.Config while getting around the
additional difficulties of encrypting the text. Thoughts? (and yes - I know
Base64 encoding is not the same as encryption - not even close).

Merk


[quoted text, click to view]

Bruce Wood
12/6/2006 11:45:35 AM

[quoted text, click to view]

I had thought of that, too. That would defeat unsophisticated, curious
users. I'm hoping to raise the bar a little higher, though....

I'm reading the article to which I linked and there indeed appear to be
solutions for WinForms applications buried in there. Haven't read
enough to arrive at an answer, yet....
AddThis Social Bookmark Button