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.

About stigzler 42 Articles
Chief crook and wattle bosher.

1 Comment

  1. Excellent blog post. I was searching for something
    completely different,
    but stumbled on your site. I am glad I did. Many thanks for sharing
    useful information. Many thanks and best of luck.

Leave a Reply

Your email address will not be published.