Click here to Skip to main content
14,028,764 members
Rate this:
Please Sign up or sign in to vote.
See more:
I want to totally hide my connection string which contains database connection<b< b="">. How to not allow retriving or viewing of sqlconnection string via.

SqlConnection con= new SqlConnectin(constring);

What I have tried:

Encryting and decrypting. Clearing Nd reinize it before using con.
Updated 5-Mar-19 14:03pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Pretty much, you can't.

The connection string has to be text, and has to be readable - that's the only format by which you can connect to a server using C#. Which means that regardless of how you store it, it has to be convertible back to a human readable string in order for you application to use it!

And that means that the conversion mechanism has to be part of your app in some way, so it can never be totally secure.

The best you can do is encrypt it using a key, convert it to Base64 so you can store it in a configuration file, and the reverse the process using the same key inside your app before you connect.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Depending on how your application is deployed can provide measures of security. Keeping the connection string in a transform variable in a web.config or app.config so that the real production connection string is only injected when the app is deployed to production is one method.

if that's not available, encrypting the string and keeping it in the app.config or web.config and decrypting it in the application code prior to connection is another possibility.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web02 | 2.8.190419.4 | Last Updated 5 Mar 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100