Automatically encrypt database connection strings in Visual Studio

This article shows you how to automatically preserve your database connection string in app.config whilst also deploying an encrypted version in your production app….

In my example, I am connecting to a remote MySQL database from a winforms app.

Add your data source via the usual means, choosing to save your password and store in app.config:

The open ProjectSettings > Compile > BuildEvents > Edit Post-build

and post the following code:

Replacing “YourAppWithoutExtention” with your app name.

Then every time it builds, it will automatically encrypt your app.config.

The last paragraph of code removes any unnecessary .pdb or .xml files. This can be removed if your app requires them.

Be the first to comment

Leave a Reply

Your email address will not be published.


*