示例#1
0
 internal Connection(Connection src)
 {
     Name = src.Name;
     ConnectionString = src.ConnectionString;
     Provider = src.Provider;
     Type = src.Type;
 }
示例#2
0
        /// <summary>
        /// Changes the connection string used.
        /// </summary>
        /// <param name="connectionStore">The connection store.</param>
        /// <param name="name">The name.</param>
        /// <param name="connectionString">The connection string.</param>
        /// <param name="providerName">Name of the provider.</param>
        /// <param name="dbType">Type of the database.</param>
        public static void ChangeConnection(object connectionStore, string name, string connectionString, string providerName, DatabaseType dbType = DatabaseType.Unset)
        {
            var newConnection = new Connection(name, connectionString, providerName, dbType);
            if (activeConnectionStorage == null)
            {
                if (connectionStore == null)
                    activeConnectionStorage = new Dictionary<string, Connection>();
                else
                    activeConnectionStorage = connectionStore;
            }

            ActiveConnection = newConnection;

            //if (ConfigurationManager.ConnectionStrings[connectionString] == null)
            //{
            //    //allow the connection string section of web.config to be written to (Memory only, not saved to disk)
            //    typeof(ConfigurationElementCollection).GetField("bReadOnly",
            //        BindingFlags.Instance | BindingFlags.NonPublic)
            //        .SetValue(ConfigurationManager.ConnectionStrings, false);
            //    switch (type)
            //    {
            //        case CPonDatabaseVendorType.SqlServer:
            //            ConfigurationManager.ConnectionStrings.Add(new ConnectionStringSettings
            //            {
            //                Name = connectionString,
            //                ConnectionString = connectionString,
            //                ProviderName = "System.Data.SqlClient"
            //            });
            //            break;
            //        case CPonDatabaseVendorType.Oracle:
            //            ConfigurationManager.ConnectionStrings.Add(new ConnectionStringSettings
            //            {
            //                Name = connectionString,
            //                ConnectionString = connectionString,
            //                ProviderName = "Oracle.ManagedDataAccess.Client"
            //            });
            //            break;
            //        default:
            //            throw new Exception("Unsupported Database Type");
            //    }
            //}

            //if (!createButDontChange)
            //{
            //    DBType = type;
            //    _connectionName = connectionString;
            //}
        }