public static CommConnection GetConnection(DataBaseName DBName, ConnectionDBType type) { String connectionstring = String.Empty; String GetDBName = String.Empty; #region Get need used database name if (DBName.ToString().StartsWith("Default")) { GetDBName = DBName.ToString().Replace("Default_", ""); } else { GetDBName = DBName.ToString().Replace("DB_", ""); } #endregion if (type == ConnectionDBType.SqlServer) { //SQL Server connectionstring = String.Format("Data Source={0};Initial Catalog={1};Persist Security Info=True;User ID={2};Password={3};MultipleActiveResultSets=True", Server, GetDBName, Account, Password); } if (type == ConnectionDBType.OleDB) { //Access String FilePath = Path + "\\_Code\\Database\\MainDB.mdb"; connectionstring = String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};", FilePath); } if (type == ConnectionDBType.MySql) { //SQL Server connectionstring = String.Format("Network Address={0};Initial Catalog='{1}';Persist Security Info=no;User Name='{2}';Password='******'", Server, GetDBName, Account, Password); } if (conn == null) { conn = new CommConnection(connectionstring, type); conn.Open(); } if (conn.State != System.Data.ConnectionState.Open) { conn.Dispose(); conn = null; conn = new CommConnection(connectionstring, type); conn.Open(); } return(conn); }
public static CommConnection GetConnection(DataBaseName DBName, ConnectionDBType type) { String connectionstring = String.Empty; String GetDBName = String.Empty; #region Get need used database name if (DBName.ToString().StartsWith("Default")) { GetDBName = DBName.ToString().Replace("Default_", ""); } else { GetDBName = DBName.ToString().Replace("DB_", ""); } #endregion if (type == ConnectionDBType.SqlServer) { //SQL Server connectionstring = String.Format("Data Source={0};Initial Catalog={1};Persist Security Info=True;User ID={2};Password={3};MultipleActiveResultSets=True", Server, GetDBName, Account, Password); } if (type == ConnectionDBType.OleDB) { //Access String FilePath = Path + "\\_Code\\Database\\MainDB.mdb"; connectionstring = String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};", FilePath); } if (type == ConnectionDBType.MySql) { //SQL Server connectionstring = String.Format("Network Address={0};Initial Catalog='{1}';Persist Security Info=no;User Name='{2}';Password='******'", Server, GetDBName, Account, Password); } if (conn == null) { conn = new CommConnection(connectionstring, type); conn.Open(); } if (conn.State != System.Data.ConnectionState.Open) { conn.Dispose(); conn = null; conn = new CommConnection(connectionstring, type); conn.Open(); } return conn; }
public CommConnection(String ConnectionString, ConnectionDBType type) { connType = type; AcceptChanges = true; if (type == ConnectionDBType.SqlServer) { SqlConn = new SqlConnection(ConnectionString); } else if (type == ConnectionDBType.OleDB) { OleConn = new OleDbConnection(ConnectionString); } else if (type == ConnectionDBType.MySql) { MySqlConn = new MySqlConnection(ConnectionString); } }