System.Data.Common.DbProviderFactories.GetFactory(System.Data.Common.DbConnection)

Here are the examples of the csharp api class System.Data.Common.DbProviderFactories.GetFactory(System.Data.Common.DbConnection) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

31 Examples 7

1. Example

View license
internal static DbProviderFactory GetProviderFactory(string providerInvariantName)
        {
            EntityUtil.CheckArgumentNull(providerInvariantName, "providerInvariantName");
            DbProviderFactory factory;
            try
            {
                factory = DbProviderFactories.GetFactory(providerInvariantName);
            }
            catch (ArgumentException e)
            {
                throw EntityUtil.Argument(Strings.EntityClient_InvalidStoreProvider, e);
            }
            return factory;
        }

2. Example

Project: referencesource
Source File: EntityConnection.cs
View license
private DbProviderFactory GetFactory(string providerString)
        {
            try
            {
                return DbProviderFactories.GetFactory(providerString);
            }
            catch (ArgumentException e)
            {
                throw EntityUtil.Argument(System.Data.Entity.Strings.EntityClient_InvalidStoreProvider, e);
            }
        }

3. Example

Project: referencesource
Source File: SqlDataSource.cs
View license
protected virtual DbProviderFactory GetDbProviderFactory() {
            string providerName = ProviderName;

            // Default to SQL provider
            if (String.IsNullOrEmpty(providerName)) {
                // use DefaultProviderName instance
                return SqlClientFactory.Instance;
            }
            else {
                return DbProviderFactories.GetFactory(providerName);
            }
        }

4. Example

Project: Susanoo
Source File: DatabaseManager.cs
View license
public static DatabaseManager CreateFromConnectionStringName(string connectionStringName)
        {
            var connectionString = ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString;

            var provider =
                DbProviderFactories.GetFactory(ConfigurationManager.ConnectionStrings[connectionStringName].ProviderName);

            var manager = new DatabaseManager
            {
                _connectionString = connectionString,
                Provider = provider
            };

            if (manager.Provider == null)
                throw new ArgumentException("Provider is a required component of the connection string.",
                    nameof(connectionStringName));

            return manager;
        }

5. Example

Project: DeclarativeSql
Source File: DbProvider.cs
View license
public static DbProviderFactory GetFactory(DbKind dbKind)
        {
            var name = dbKind.GetProviderName();
            return DbProviderFactories.GetFactory(name);
        }

6. Example

View license
public static DbProviderFactory GetDbProviderFactory(this System.Data.Entity.Database database)
        {
            Check.NotNull(database);
            DbConnection connection = database.Connection;
            DbProviderFactory factory = DbProviderFactories.GetFactory(connection);
            return factory;
        }

7. Example

View license
public static DbProviderFactory GetProviderFactory(DbConnection connection)
        {
            EntityUtil.CheckArgumentNull(connection, "connection");
            DbProviderFactory factory = DbProviderFactories.GetFactory(connection);
            if (factory == null)
            {
                throw EntityUtil.ProviderIncompatible(System.Data.Entity.Strings.EntityClient_ReturnedNullOnProviderMethod(
                        "get_ProviderFactory",
                        connection.GetType().ToString()));
            }
            Debug.Assert(factory != null, "Should have thrown on null"); 
            return factory;
        }

8. Example

View license
public static EntityConnection CreateStoreSchemaConnection(string providerInvariantName, string conn/n ..... /n //View Source file for more details /n }

9. Example

View license
private DbConnection GetDbConnection(EntityConnectionStringBuilder connStrBuilder)
        {
       /n ..... /n //View Source file for more details /n }

10. Example

Project: anycmd
Source File: RdbDescriptor.cs
View license
public DbParameter CreateParameter()
        {
            if (_dbProviderFactory == null)
            {
                _dbProviderFactory = DbProviderFactories.GetFactory(Database.ProviderName);
            }
            return _dbProviderFactory.CreateParameter();
        }

11. Example

View license
internal static bool ConnectionStringEquals(DbConnection connection, string connectionString)
        {
            DbProviderFactory factory = DbProviderFactories.GetFactory(connection);
            DbConnectionStringEqualityComparer comparer = GetConnectionStringEqualityComparer(factory);
            return comparer.Equals(connection.ConnectionString, connectionString);
        }

12. Example

View license
protected void StartServersStateScanIfNeed(System.Data.Entity.DbContext context)
        {
            lock (this._locker)
            {
                if (this._taskIsRunning)
                    return;

                Type contextType = context.GetType();
                DbProviderFactory factory = DbProviderFactories.GetFactory(context.Database.Connection);
                this.Config.StartDbServersStateScanTaskIfNeed(factory);

                this._taskIsRunning = true;
            }
        }

13. Example

Project: EasyNetQ
Source File: ScheduleRepository.cs
View license
private IDbConnection GetConnection()
        {
            var factory = DbProviderFactories.GetFactory(configuration.ProviderName);
            var connection = factory.CreateConnection();
            connection.ConnectionString = configuration.ConnectionString;
            connection.Open();
            return connection;
        }

14. Example

Project: DbExtensions
Source File: Database.cs
View license
DbCommandBuilder CreateCommandBuilder(string providerInvariantName) {

         DbConnection dbConn = this.Connection as DbConnection;

         DbProviderFactory factory = ((dbConn != null) ? DbProviderFactories.GetFactory(dbConn) : null)
            ?? GetProviderFactory(providerInvariantName);

         return factory.CreateCommandBuilder();
      }

15. Example

Project: MIMWAL
Source File: ExpressionFunction.cs
View license
private DbParameter CreateSqlParameter()
        {
            Logger.Instance.WriteMethodEntry(Even/n ..... /n //View Source file for more details /n }

16. Example

Project: referencesource
Source File: SqlProvider.cs
View license
private static DbProviderFactory GetProvider(string providerName) {
            bool hasProvider = 
                DbProviderFactories.GetFactoryClasses().Rows.OfType<DataRow>()
                .Select(r => (string)r["InvariantName"])
                .Contains(providerName, StringComparer.OrdinalIgnoreCase);
            if (hasProvider) {
                return DbProviderFactories.GetFactory(providerName);
            }
            return null;
        }

17. Example

Project: anycmd
Source File: RdbDescriptor.cs
View license
public DbConnection GetConnection()
        {
            if (_dbProviderFactory == null)
            {
                _dbProviderFactory = DbProviderFactories.GetFactory(Database.ProviderName);
            }
            var conn = _dbProviderFactory.CreateConnection();
            Debug.Assert(conn != null, "conn != null");
            conn.ConnectionString = ConnString;

            return conn;
        }

18. Example

View license
private bool ConnectionStringCompare(DbConnection conn, string connectionString)
        {
            DbProviderFactory factory = DbProviderFactories.GetFactory(conn);

            DbConnectionStringBuilder a = factory.CreateConnectionStringBuilder();
            a.ConnectionString = conn.ConnectionString;

            DbConnectionStringBuilder b = factory.CreateConnectionStringBuilder();
            b.ConnectionString = connectionString;

            return a.EquivalentTo(b);
        }

19. Example

Project: eve-plh
Source File: PetaPoco.cs
View license
private void CommonConstruct()
		{
			// Reset
			_transactionDepth = 0;
			EnableAutoSelect = true;
			EnableNamedParams = true;

			// If a provider name was supplied, get the IDbProviderFactory for it
			if (_providerName != null)
				_factory = DbProviderFactories.GetFactory(_providerName);

			// Resolve the DB Type
			string DBTypeName = (_factory == null ? _sharedConnection.GetType() : _factory.GetType()).Name;
			_dbType = DatabaseType.Resolve(DBTypeName, _providerName);

			// What character is used for delimiting parameters in SQL
			_paramPrefix = _dbType.GetParameterPrefix(_connectionString);
		}

20. Example

View license
public static bool IsConnectionAvailable(string connString, DatabaseProviders provider)
        {
            DbProviderFactory factory;
            switch (provider)
            {
                case DatabaseProviders.SqlServer:
                case DatabaseProviders.SqlAzure:
                    factory = DbProviderFactories.GetFactory(Constants.DatabaseProviders.SqlServer);
                    break;
                case DatabaseProviders.SqlServerCE:
                    factory = DbProviderFactories.GetFactory("System.Data.SqlServerCe.4.0");
                    break;
                case DatabaseProviders.MySql:
                    factory = DbProviderFactories.GetFactory(Constants.DatabaseProviders.MySql);
                    break;
                case DatabaseProviders.PostgreSQL:
                case DatabaseProviders.Oracle:
                case DatabaseProviders.SQLite:                    
                default:
                    throw new NotSupportedException("The provider " + provider + " is not supported");
            }

            var conn = factory.CreateConnection();
            if (conn == null)
            {
                throw new InvalidOperationException("Could not create a connection for provider " + provider);
            }
            conn.ConnectionString = connString;
            using (var connection = conn)
            {
                return connection.IsAvailable();
            }
        }

21. Example

Project: referencesource
Source File: EntityUtil.cs
View license
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
        internal sta/n ..... /n //View Source file for more details /n }

22. Example

View license
public bool CheckDbConnection()
        {
            //
            // Clear all pool connected  (connection without reference address)
            SqlConnection.ClearAllPools();
            //
            // Check connection string validation
            if (string.IsNullOrEmpty(ConnectionString) || !IsServerOnline()) return IsReady = false;
            //
            // Try to Create provider factory for connect to Database
            try
            {
                DbProviderFactories.GetFactory(Connection.ProviderName);
            }
            catch
            {
                return IsReady = false;
            }

            //
            // try to connection to database and open link:
            try
            {
                Open();

                IsReady = (State == ConnectionState.Open);
            }
            catch
            {
                IsReady = false;
            }
            finally
            {
                Close();
            }

            return IsReady;
        }

23. Example

View license
public async Task<bool> CheckDbConnectionAsync()
        {
            //
            // Clear all pool connected  (connection without reference address)
            SqlConnection.ClearAllPools();
            //
            // Check connection string validation
            if (string.IsNullOrEmpty(ConnectionString) || !await IsServerOnlineAsync()) return IsReady = false;
            //
            // Try to Create provider factory for connect to Database
            try
            {
                DbProviderFactories.GetFactory(Connection.ProviderName);
            }
            catch
            {
                return IsReady = false;
            }

            //
            // try to connection to database and open link:
            try
            {
                await OpenAsync();

                IsReady = (State == ConnectionState.Open);
            }
            catch
            {
                IsReady = false;
            }
            finally
            {
                Close();
            }

            return IsReady;
        }

24. Example

Project: DotnetSpider
Source File: DatabaseExtensions.cs
View license
public static DbConnection GetDbConnection(this ConnectionStringSettings connectionStringSettings)
		{
			if (connectionStringSettings == null)
			{
				throw new SpiderException("ConnectionStringSetting is null.");
			}
			if (string.IsNullOrEmpty(connectionStringSettings.ConnectionString) || string.IsNullOrEmpty(connectionStringSettings.ProviderName))
			{
				throw new SpiderException("ConnectionStringSetting is incorrect.");
			}

			var factory = DbProviderFactories.GetFactory(connectionStringSettings.ProviderName);

			for (int i = 0; i < 5; ++i)
			{
				try
				{
					DbConnection connection = factory.CreateConnection();
					if (connection != null)
					{
						connection.ConnectionString = connectionStringSettings.ConnectionString;
						connection.Open();
						return connection;
					}
				}
				catch (Exception e)
				{
					if (e.Message.ToLower().StartsWith("authentication to host"))
					{
						Logger.AllLog($"{e}", LogLevel.Error);
						Thread.Sleep(1000);
					}
					else
					{
						//throw;
					}
				}
			}

			throw new SpiderException("Can't get db connection.");
		}

25. Example

Project: MIMWAL
Source File: ExpressionFunction.cs
View license
[SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily", Justification = "Reviewed/n ..... /n //View Source file for more details /n }

26. Example

Project: referencesource
Source File: ObjectContext.cs
View license
public virtual Int32 SaveChanges(SaveOptions options)
        {
            ObjectStateManager.Asser/n ..... /n //View Source file for more details /n }

27. Example

View license
public IEnumerable<IList<CellData>> Rows()
        {
            var factory = DbProvide/n ..... /n //View Source file for more details /n }

28. Example

Project: MIMWAL
Source File: ExpressionFunction.cs
View license
[SuppressMessage("Microsoft.Security", "CA2100:Review SQL queries for security vulnerabilities", Jus/n ..... /n //View Source file for more details /n }

29. Example

Project: Xploit
Source File: DatabaseQuery.cs
View license
public override bool Run()
        {
            DbConnection db = Get();
            if (db == null/n ..... /n //View Source file for more details /n }

30. Example

View license
private IList<IList<dynamic>> ExecuteCommands()
        {
            Contract.Requires(/n ..... /n //View Source file for more details /n }

31. Example

View license
private IList<IList<dynamic>> ExecuteCommands()
        {
            Contract.Requires(/n ..... /n //View Source file for more details /n }