public static void Clone(Connection source, Connection destination) { // exceptions if (source == null) throw new ArgumentNullException("source"); if (destination == null) throw new ArgumentNullException("destination"); // copy each value over foreach (var pi in source.GetType().GetProperties() .Where(pi => pi.CanRead && pi.CanWrite && pi.Name != "ConnectionString")) pi.SetValue(destination, pi.GetValue(source, null), null); }
public static Connection ParseConnectionString(string connectionString) { if (connectionString.StartsWith("#")) // if connection string starts with '#' then it's Encrypted ! connectionString = connectionString.Substring(1).Decrypt(); var scsb = new SqlConnectionStringBuilder(connectionString); var conn = new Connection { Server = scsb.DataSource, DatabaseName = scsb.InitialCatalog, TimeOut = connectionString.Contains("Connection Timeout") ? scsb.ConnectTimeout : 0, UserId = scsb.UserID, Password = scsb.Password, PortNumber = 1433, AttachDbFilename = scsb.AttachDBFilename, PersistSecurityInfo = scsb.PersistSecurityInfo, AppName = scsb.ApplicationName, IntegratedSecurity = scsb.IntegratedSecurity ? connectionString.Substring(connectionString.IndexOf("Integrated Security=", System.StringComparison.Ordinal) + "Integrated Security=".Length, 4) : "false" }; return conn; }
public object Clone() { var connObj = new Connection(); // copy each value over Clone(this, connObj); return connObj; }
/// <summary> /// Initializes a new instance of the <see cref="Connection"/> class. /// </summary> /// <param name="conn">The connection object.</param> public Connection(Connection conn) { Clone(conn, this); }