Best Practice for storing connection strings in .net C# WIndows form applications.

Can someone tell me what the Best Practice is for storing connection strings in .net C# WIndows form applications.  I have a windows applications with several window forms that refer to EXCEL and SQL server connection strings.  How do you make these global in window form applications?

 strConnectionString = ExcelCon + "Data Source=" + strFileName + ";Extended Properties=" + Convert.ToChar(34).ToString() + "Excel 8.0;HDR=Yes;IMEX=1" + Convert.ToChar(34).ToString();

string cons = "Data Source=(local);Initial Catalog=MyDB;Integrated Security=SSPI;";
Who is Participating?

The best place to store connection string is "always" in configuration file.

Please go through following link.

Let us know, if you still find difficutly.

Kind Regards,
When a server administrator migrates a DataBase or change the password for a Schema, it needs also migrate each Config.App for each user application.

I think this is´nt the best solution.

I use a Network-File to store a DataSet (Binary formatter) with Information about Connection Strings for some applications. Only Admistrator has write privileges for this archive.

Config.App has a variable that points to Network-File and other for the selected Connection-String.

I would say go with the config files (as mentioned above) along with encryption.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.