Created
January 10, 2017 07:38
-
-
Save gracefullight/13b73099ce330665e9754f38887a0d8a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using MySql.Data.MySqlClient; | |
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Threading; | |
| using System.Web; | |
| namespace WebApplication.ClassFolder{ | |
| public class DBConfig{ | |
| private static string Server = ""; | |
| private static string Database = ""; | |
| private static string ID = ""; | |
| private static string PASS = ""; | |
| static string conf = "Server=" + Server + ";Database=" + Database + ";Uid=" + ID + ";Pwd=" + PASS; | |
| static MySqlConnection db; | |
| public static MySqlConnection Connection{ | |
| get{ | |
| if (db == null){ | |
| LazyInitializer.EnsureInitialized(ref db, CreateConnection); | |
| } | |
| return db; | |
| } | |
| } | |
| static MySqlConnection CreateConnection(){ | |
| var db = new MySqlConnection(conf); | |
| db.Open(); | |
| return db; | |
| } | |
| // 강제로 커넥션을 끊어야될 경우가 있을 때 | |
| static void CloseConnection(){ | |
| if(db != null) { | |
| db.Close(); | |
| db.Dispose(); | |
| db = null; | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment