Esempio n. 1
0
        /// <inheritdoc />
        public IDbConnection GetConnection()
        {
            Drivers.LoadDrivers(this.config.GetDrivers());
            var factory    = DbProviderFactories.GetFactory(this.settings.ProviderName);
            var connection = factory.CreateConnection();

            if (connection == null)
            {
                throw new SqlEditorException(
                          "Can not get iDbConnection from configuration settings. " +
                          "Please check provider name of " + this.settings.ProviderName);
            }

            connection.ConnectionString = this.settings.ConnectionString;

            return(connection);
        }
Esempio n. 2
0
        /// <inheritdoc />
        public bool TryConnect(string username, string password)
        {
            Drivers.LoadDrivers(this.config.GetDrivers());
            IDbConnection conn = null;

            try
            {
                conn = this.GetConnection();
                if (this.IsLoginRequired())
                {
                    conn.ConnectionString = this.GetUserConnectionString(username, password).ConnectionString;
                }

                conn.Open();
                return(true);
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
        }