예제 #1
0
        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);
        }
예제 #2
0
        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;
        }
예제 #3
0
        public object Clone()
        {
            var connObj = new Connection();

            // copy each value over
            Clone(this, connObj);

            return connObj;
        }
예제 #4
0
 /// <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);
 }