Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

How can I protect the use name and password in ConnectionString?

In order to connect to database, I have to put the name and password in ConnectionString, I know the C# program can be uncompiled easily,
how can I the use name and password? thanks!
[187 byte] By [mycwcgr] at [2007-11-11 6:42:21]
# 1 Re: How can I protect the use name and password in ConnectionString?
http://weblogs.asp.net/owscott/archive/2005/07/29/421063.aspx
Phil Weber at 2007-11-11 20:48:41 >
# 2 Re: How can I protect the use name and password in ConnectionString?
I just simply put the connectionstring (together with the user ID and password) in the Application Settings section of the web.config file.

Is it OK?
THL at 2007-11-11 20:49:41 >
# 3 Re: How can I protect the use name and password in ConnectionString?
It's OK until someone hacks your Web server. ;-)
Phil Weber at 2007-11-11 20:50:44 >
# 4 Re: How can I protect the use name and password in ConnectionString?
I just simply put the connectionstring (together with the user ID and password) in the Application Settings section of the web.config file.

Is it OK?

It's a windows application, not ASP.net, so no web.config
mycwcgr at 2007-11-11 20:51:50 >
# 5 Re: How can I protect the use name and password in ConnectionString?
Windows apps can use config files as well: they're named <filename>.exe.config, where <filename> is the name of your app's .EXE file. The config file should be deployed to the same directory as the .EXE.
Phil Weber at 2007-11-11 20:52:44 >
# 6 Re: How can I protect the use name and password in ConnectionString?
http://weblogs.asp.net/owscott/archive/2005/07/29/421063.aspx

Thanks Phil, but... how can I implement the same solution for app.config? (winform app)

TIA,

Carlos A. Granitto
MCP
CarlosGranitto at 2007-11-11 20:53:43 >
# 7 Re: How can I protect the use name and password in ConnectionString?
Not sure which version of .NET you are using but the following is for 2005:

http://www.developer.com/net/vb/article.php/3500906
http://msdn2.microsoft.com/en-us/library/89211k9b(VS.80).aspx

You could also try the following:

http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=7D1D4954-A530-4329-8CC0-96A0C39AB4B2
pclement at 2007-11-11 20:54:47 >
# 8 Re: How can I protect the use name and password in ConnectionString?
Yes, I'm using VS2005.

Thanks a lot Paul!
CarlosGranitto at 2007-11-11 20:55:45 >