I am new to windows forms programming and I was wondering what would be the best way to create like a connectionstring.config (i dont know how to do this) I have seens it , its like an xml giving all the information to connect to the database, in my case I am connecting to a MySql database. I would like to have so i could do something like this (I KNOW THIS IS WRONG BUT YOU GET MY IDEA):
MySqlConnection conn = new MySqlConnection
(Someconfiguration.thatconnects.toMyXMLOrSomething["MyXMLFile]);
something like that, i know i am probably too far from what it is.. but I have seen this somewhere and i think its clean, instead of putting the data connection information everywhere i need it.
so a few questions:
- How do i create that xml file in VS2010?
- Where do I place that file?
- How should I call it in the functions where i am using it?.
I would really appreciate all the possible help as I am learning and would like to keep everything separate and clean like this.
Thank you for your help and valuable time to help me.
You can put them in a specific node inside your app.config file.
Here’s the MSDN documentation for adding the app.config file to your project and it includes adding connection strings: http://msdn.microsoft.com/en-us/library/ms243192(v=vs.100).aspx
You can then use the built in .NET ConfigurationManager class to pull it out: