Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MySqlConnection connection = new MySqlConnection(MyConString);
- public class ConnectionFactory
- {
- public static MySqlConnection Create()
- {
- string connectionString = ConfigurationManager.AppSettings["..."];
- MySqlConnection conection = new MySqlConnection(Config.ConnectionStr);
- connection.Open();
- return connection;
- }
- }
- private void button1_click(object sender, EventArg args)
- {
- using ( var connection = ConnectionFactory.Create() )
- {
- connection.Execute("...");
- }
- }
- public static class Config
- {
- public static string ConnectionStr = ConfigurationManager.AppSettings["..."];
- }
- MySqlConnection connection = new MySqlConnection(Config.ConnectionStr);
- static void GetConnectionStrings()
- {
- var settings = ConfigurationManager.ConnectionStrings;
- if (settings != null) {
- foreach(ConnectionStringSettings cs in settings) {
- Console.WriteLine(cs.Name);
- Console.WriteLine(cs.ProviderName);
- Console.WriteLine(cs.ConnectionString);
- }
- }
- }
- // Returns null if the name is not found.
- static string GetConnectionStringByName(string name)
- {
- string returnValue = null; // Assume failure.
- var settings = ConfigurationManager.ConnectionStrings[name];
- if (settings != null) {
- returnValue = settings.ConnectionString;
- }
- return returnValue;
- }
Add Comment
Please, Sign In to add comment