473,413 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

Encrypting Connection Strings in app.config

I'm trying to encrypt a connection string in an app.config.

This is the app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="test" connectionString="user
id=testuser;password=testpwd;data source=testdb;persist security
info=False;"/>
</connectionStrings>
</configuration>

Here's the code:

private void btnEncrypt_Click(object sender, EventArgs e)
{
Configuration config =
ConfigurationManager.OpenExeConfiguration(Configur ationUserLevel.None);

ConnectionStringsSection section =
(ConnectionStringsSection)
config.GetSection("connectionStrings");

if (!section.SectionInformation.IsProtected)

section.SectionInformation.ProtectSection("DataPro tectionConfigurationProvider");

config.Save(ConfigurationSaveMode.Full);

txtDisplay.Text = "Encrypted";

}

I have
using System.Configuration;
at the top and a reference to System.Configuration in the references.

When I run it, it displays the "encrypted" message. There are no errors and
it completes, yet the app,.config section is not encrypted.

Any help is appreciated.

Thanks,

Mike
May 21 '07 #1
1 5888

"Mike Robbins" <Mi*********@discussions.microsoft.comwrote in message
news:C3**********************************@microsof t.com...
I'm trying to encrypt a connection string in an app.config.
<snipped>
I have
using System.Configuration;
at the top and a reference to System.Configuration in the references.

When I run it, it displays the "encrypted" message. There are no errors
and
it completes, yet the app,.config section is not encrypted.
Are you sure you're looking at the right config file?

There is the app.config file, and then there is the appnamerun.config file
that's located at the location of the exe that holds the app.config data at
runtime, which ConfigurationManager can manipulate.

May 21 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: stewart | last post by:
I've got the standard SqlCacheDependency working just fine , ie. I've defined (and encrypted) the connectionStrings section in the web.config, and I've also defined an an sqlCacheDependency in the...
7
by: Gary Brizard | last post by:
OK. For an n-tier architecture, where is the best place to store the connection string for the DA layer? I don't want to use the reg. Can't use a app.config for a dll. For other projects I...
4
by: Matt Colegrove | last post by:
I'm working on a web app that is published to a hosting service. I'm developing it on my local PC with VS 2005 and SQL Express. The hosting service DB is SQL Server 2000. I have two...
1
by: girthyvhf | last post by:
Hello all, I am trying to use the example for encrypting connection strings called: How To: Build And Run the Protected Configuration Provider Example. This is located in VS 2005 help at: ...
5
by: Chris Dunaway | last post by:
I have an application which is installed on a network share to be run from one or more workstations. I have granted trust to the applications on the workstations and the appropriate permissions on...
1
by: vikram | last post by:
How can we encrypt app.comfig keys in .net 2003 ? Thanks
9
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I have a question about storing the connection strings to the database in a config file or database. My manager wants me to store all the connection strings in a database, but I...
1
by: Amy L. | last post by:
I have a .Net 2.0 windows forms application where a user will supply a connection string for their database server during initial configuration. I want to make sure this string is encrypted when...
2
by: Johnson | last post by:
I'm trying to fix a "sub optimal" situation with respect to connection string management. Your thoughtful responses will be appreciated. I just started with a new client who has a bunch of legacy...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.