/// <summary> /// Open /// </summary> /// <param name="SQLConnectionString"></param> /// <returns>bool</returns> public bool Open(SQLConnectionString sqlConnectionString) { try { if (sqlConnectionString.ServerName == string.Empty || sqlConnectionString.ServerName == null || sqlConnectionString.DatabaseName == string.Empty || sqlConnectionString.DatabaseName == null) { throw new Exception("ConnectionString missing ServerName or DatabaseName value."); } this.connectionString = this.ConnectionStringBuilder(sqlConnectionString); this.sqlDbConnection = new SqlConnection(); this.sqlDbConnection.ConnectionString = this.connectionString; this.Open(); return(true); } catch (Exception ex) { this.ErrorLog(ex); return(false); } }
/// <summary> /// ConnectionStringBuilder /// </summary> /// <param name="SQLConnectionString"></param> /// <returns>string</returns> protected string ConnectionStringBuilder(SQLConnectionString sqlConnectionString) { StringBuilder tmpString = new StringBuilder(); string tmpResult; tmpString.Append("Persist Security Info="); tmpString.Append(sqlConnectionString.PersistSecurityInfo); tmpString.Append(";Integrated Security="); if (sqlConnectionString.IntegratedSecurity == string.Empty) { tmpString.Append("SSPI"); } else { tmpString.Append(sqlConnectionString.IntegratedSecurity); if (sqlConnectionString.IntegratedSecurity == "false") { tmpString.Append(";UID="); tmpString.Append(sqlConnectionString.UserID); tmpString.Append(";Password="******";database="); tmpString.Append(sqlConnectionString.DatabaseName); tmpString.Append(";server="); tmpString.Append(sqlConnectionString.ServerName); if (sqlConnectionString.ConnectTimeout != 0) { tmpString.Append(";Connect Timeout="); tmpString.Append(sqlConnectionString.ConnectTimeout); } if (sqlConnectionString.Pooling) { tmpString.Append(";Pooling="); tmpString.Append(sqlConnectionString.Pooling); if (sqlConnectionString.MaxPoolSize != 0) { tmpString.Append(";Max Pool Size="); tmpString.Append(sqlConnectionString.MaxPoolSize); } } tmpResult = tmpString.ToString(); tmpString.Remove(0, tmpString.Length); tmpString = null; return(tmpResult); }