コード例 #1
0
        /// <summary>
        /// Gets the SQL connection.
        /// </summary>
        /// <param name="connectionDetails">Connection details.</param>
        /// <returns>Returns the SQL connection.</returns>
        public SqlConnection GetSqlConnection(ConnectionDetailsElement connectionDetails)
        {
            //  Gets the SQL connection string.
            var connectionString = this.GetConnectionString(connectionDetails);

            return(new SqlConnection(connectionString));
        }
コード例 #2
0
        /// <summary>
        /// Gets the database connection through entity framework.
        /// </summary>
        /// <param name="connectionDetails">Connection details.</param>
        /// <returns>Returns the database connection through entity framework.</returns>
        public EntityConnection GetEntityConnection(ConnectionDetailsElement connectionDetails)
        {
            //  Gets the SQL connection string builder.
            var connectionString = this.GetConnectionString(connectionDetails);

            //  Gets the entity framework connection string builder.
            var efBuilder = new EntityConnectionStringBuilder()
            {
                Provider = connectionDetails.Provider,
                ProviderConnectionString = connectionString,
                Metadata = String.Format(@"res://*/{0}.csdl|res://*/{0}.ssdl|res://*/{0}.msl",
                                         connectionDetails.DataContext)
            };

            return(new EntityConnection(efBuilder.ToString()));
        }
コード例 #3
0
        /// <summary>
        /// Gets the database connection string.
        /// </summary>
        /// <param name="connectionDetails">Connection details.</param>
        /// <returns>Returns the database connection string.</returns>
        public string GetConnectionString(ConnectionDetailsElement connectionDetails)
        {
            if (connectionDetails == null)
            {
                throw new ArgumentNullException("connectionDetails", "No connection details provided");
            }

            if (!connectionDetails.Use)
            {
                throw new ArgumentException("Connection details no longer used");
            }

            //  Gets the SQL connection string builder.
            var sqlBuilder = new SqlConnectionStringBuilder()
            {
                //  Advanced
                MultipleActiveResultSets = connectionDetails.MultipleActiveResultSets,
                //NetworkLibrary = connectionDetails.NetworkLibrary,
                PacketSize         = connectionDetails.PacketSize,
                TransactionBinding = connectionDetails.TransactionBinding,
                TypeSystemVersion  = connectionDetails.TypeSystemVersion,

                //  Context
                ApplicationName = connectionDetails.ApplicationName,
                WorkstationID   = connectionDetails.WorkstationId,

                //  Initialisation
                //ApplicationIntent = connectionDetails.ApplicationIntent,
                AsynchronousProcessing = connectionDetails.AsynchronousProcessing,
                ConnectTimeout         = connectionDetails.ConnectionTimeout,
                CurrentLanguage        = connectionDetails.CurrentLanguage,

                //  Pooling
                Enlist             = connectionDetails.Enlist,
                LoadBalanceTimeout = connectionDetails.LoadBalanceTimeout,
                MaxPoolSize        = connectionDetails.MaxPoolSize,
                MinPoolSize        = connectionDetails.MinPoolSize,
                Pooling            = connectionDetails.Pooling,

                //  Replication
                Replication = connectionDetails.Replication,

                //  Security
                IntegratedSecurity     = connectionDetails.IntegratedSecurity,
                Password               = connectionDetails.IntegratedSecurity ? String.Empty : connectionDetails.Password,
                PersistSecurityInfo    = connectionDetails.PersistSecurityInfo,
                TrustServerCertificate = connectionDetails.TrustServerCertificate,
                UserID = connectionDetails.IntegratedSecurity ? String.Empty : connectionDetails.UserId,

                //  Source
                AttachDBFilename  = connectionDetails.AttachDbFilename,
                ContextConnection = connectionDetails.ContextConnection,
                DataSource        = connectionDetails.DataSource,
                FailoverPartner   = connectionDetails.FailoverPartner,
                InitialCatalog    = connectionDetails.InitialCatalog,
                //MultiSubnetFailover = connectionDetails.MultiSubnetFailover,
                UserInstance = connectionDetails.UserInstance
            };
            var connectionString = sqlBuilder.ToString();

            //if (!String.IsNullOrWhiteSpace(connectionDetails.ApplicationIntent))
            //{
            //    if (!connectionString.EndsWith(";"))
            //        connectionString += ";";

            //    connectionString += String.Format("ApplicationIntent={0}", connectionDetails.ApplicationIntent);
            //}
            //connectionString += String.Format("MultiSubnetFailover={0}", connectionDetails.MultiSubnetFailover);

            return(connectionString);
        }
コード例 #4
0
 /// <summary>
 /// Adds an key/value pair element to the ConfigurationElementCollection.
 /// </summary>
 /// <param name="element">Item element.</param>
 public void Add(ConnectionDetailsElement element)
 {
     BaseAdd(element);
 }