public static ConnectionStringInfo GetConnectionStringInfo(string connectionString, string providerName = null, DbProviderFactory factory = null)
        {
            var info = new ConnectionStringInfo();

            if (string.IsNullOrEmpty(connectionString))
            {
                throw new InvalidOperationException("AConnectionStringMustBePassedToTheConstructor");
            }

            if (!connectionString.Contains("="))
            {
                throw new ArgumentException("Connection string names are not supported with .NET Standard. Please use a full connectionstring.");
            }
            else
            {
                info.Provider = factory;

                if (factory == null)
                {
                    if (providerName == null)
                    {
                        providerName = DefaultProviderName;
                    }

                    info.Provider = SqlClientFactory.Instance;
                }
            }

            info.ConnectionString = connectionString;

            return(info);
        }
        public void GetConnectionInfo(string connectionString, string providerName = null)
        {
            // throws if connection string is invalid or missing
            var connInfo = ConnectionStringInfo.GetConnectionStringInfo(connectionString, providerName);

            ConnectionString = connInfo.ConnectionString;
            dbProvider       = connInfo.Provider;
        }
        public virtual bool OpenConnection()
        {
            try
            {
                if (_Connection == null)
                {
                    if (ConnectionString.Contains("="))
                    {
                        _Connection = dbProvider.CreateConnection();
                        _Connection.ConnectionString = ConnectionString;
                    }
                    else
                    {
                        var connInfo = ConnectionStringInfo.GetConnectionStringInfo(ConnectionString);
                        if (connInfo == null)
                        {
                            SetError("InvalidConnectionString");

                            if (ThrowExceptions)
                            {
                                throw new ApplicationException(ErrorMessage);
                            }

                            return(false);
                        }

                        dbProvider       = connInfo.Provider;
                        ConnectionString = connInfo.ConnectionString;

                        _Connection = dbProvider.CreateConnection();
                        _Connection.ConnectionString = ConnectionString;
                    }
                }

                if (_Connection.State != ConnectionState.Open)
                {
                    _Connection.Open();
                }
            }
            catch (DbException ex)
            {
                SetError(string.Format("ConnectionOpeningFailure", ex.Message));
                return(false);
            }
            catch (Exception ex)
            {
                SetError(string.Format("ConnectionOpeningFailure", ex.GetBaseException().Message));
                return(false);
            }

            return(true);
        }