Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where Should I Store a database Connection String? [closed]

Tags:

c#

mysql

wpf

I created an application in C# + WPF + MySQL. What is the best (safest) way to store database connection strings?

like image 258
Mediator Avatar asked Nov 14 '10 10:11

Mediator


People also ask

Where should you store the connection string information?

Connection strings in configuration files are typically stored inside the <connectionStrings> element in the app. config for a Windows application, or the web. config file for an ASP.NET application.

When should a database connection be closed?

If you have a valid reason to keep it open, then do so. If not, close it as soon as you're done with it. But it's better to be in the good habit of closing the connections so that you don't just leave them open when you don't intend to.

Is it safe to store connection string in web config?

config file, instead of hard coding it. But I find it very dangerous, especially in cases where the same connection string is used for all users. This means anyone who's got access to the web config file can easily get the username and password to the database and do all kinds of serious things.

Which file should the connection string be stored in so that it may be accessed from all web pages for the same application?

ANSWER: In Web. config file.


2 Answers

Store it on your App.config file and always encrypt it. This link will show you how to encrypt parts of your configuration file.

like image 128
Fernando Avatar answered Oct 03 '22 23:10

Fernando


You could store connections strings in the configuration file. You may secure them if necessary.

like image 26
Darin Dimitrov Avatar answered Oct 04 '22 01:10

Darin Dimitrov