Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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);
Messagebox.Show(con.ConnectionString);

What I have tried:

Encryting and decrypting. Clearing Nd reinize it before using con.
Posted
Updated 5-Mar-19 14:03pm

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.
 
Share this answer
 
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900