System.Data.Common.DbProviderFactory.CreateConnection()

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

168 Examples 7

1. Example

View license
public override DbConnection CreateConnection()
        {
            var connection = _dbProviderFactory.CreateConnection();
            if (connection == null)
            {
                return null;
            }

            var profiledConnection = connection as ProfiledDbConnection;
            if (profiledConnection != null)
            {
                return profiledConnection;
            }

            return new ProfiledDbConnection(connection, _dbProfiler);
        }

2. Example

Project: fluentmigrator
Source File: DbFactoryBase.cs
View license
public IDbConnection CreateConnection(string connectionString)
        {
            var connection = Factory.CreateConnection();
            connection.ConnectionString = connectionString;
            return connection;
        }

3. Example

Project: Dos.ORM
Source File: Database.cs
View license
public DbConnection CreateConnection()
        {
            DbConnection newConnection = dbProvider.DbProviderFactory.CreateConnection();
            newConnection.ConnectionString = ConnectionString;

            return newConnection;
        }

4. Example

Project: Dos.ORM
Source File: Database.cs
View license
public DbConnection CreateConnection()
        {
            DbConnection newConnection = dbProvider.DbProviderFactory.CreateConnection();
            newConnection.ConnectionString = ConnectionString;

            return newConnection;
        }

5. Example

Project: Dos.ORM
Source File: Database.cs
View license
public DbConnection CreateConnection()
        {
            DbConnection newConnection = dbProvider.DbProviderFactory.CreateConnection();
            newConnection.ConnectionString = ConnectionString;

            return newConnection;
        }

6. Example

Project: yadal
Source File: Db.cs
View license
private IDbConnection CreateConnection() => _connectionFactory.CreateConnection(_connectionString);

7. Example

Project: yadal
Source File: DbProviderFactoryEx.cs
View license
public static IDbConnection CreateConnection(this DbProviderFactory factory, string connectionString)
        {
            var connection = factory.CreateConnection();
            // ReSharper disable once PossibleNullReferenceException
            connection.ConnectionString = connectionString;
            return connection;
        }

8. Example

Project: yadal
Source File: Db.cs
View license
public static IDbConnection CreateConnection(this DbProviderFactory factory, string connectionString)
        {
            var connection = factory.CreateConnection();
            // ReSharper disable once PossibleNullReferenceException
            connection.ConnectionString = connectionString;
            return connection;
        }

9. Example

Project: dotnetmigrations
Source File: DataAccess.cs
View license
private DbConnection GetConnection(string connectionString)
        {
            DbConnection conn = _factory.CreateConnection();
            if (conn == null)
            {
                throw new InvalidOperationException("Factory failed to create connection. Returned null.");
            }

            conn.ConnectionString = connectionString;

            return conn;
        }

10. Example

Project: Kalman.Studio
Source File: Database.cs
View license
public virtual DbConnection CreateConnection()
        {
            DbConnection newConnection = _DbProviderFactory.CreateConnection();
            newConnection.ConnectionString = ConnectionString;

            return newConnection;
        }

11. Example

View license
public DbConnection CreateConnection()
		{
			return dbProviderFactory.CreateConnection();
		}

12. Example

Project: Weed3
Source File: DbContext.cs
View license
public DbConnection getConnection() {
            DbConnection conn = _provider.CreateConnection();

            conn.ConnectionString = _url;
            return conn;
        }

13. Example

Project: Weed3
Source File: DbContext.cs
View license
public DbConnection getConnection() {
            DbConnection conn = _provider.CreateConnection();

            conn.ConnectionString = _url;
            return conn;
        }

14. Example

View license
public override DbConnection CreateConnection()
        {
            return new ProfiledDbConnection(tail.CreateConnection(), profiler);
        }

15. Example

Project: Piranha
Source File: Database.cs
View license
private static IDbConnection GetConnection(string name) {
			IDbConnection conn = _factory.CreateConnection();
			conn.ConnectionString = ConfigurationManager.ConnectionStrings[name].ConnectionString;
			return conn;
		}

16. Example

Project: Radical
Source File: DataBase.cs
View license
protected virtual IDbConnection GetConnection()
        {
            if( this.connection != null )
            {
                return this.connection;
            }
            else if( this.providerFactory != null )
            {
                IDbConnection conn = this.providerFactory.CreateConnection();
                conn.ConnectionString = this.connectionString;

                return conn;
            }
            else
            {
                throw new InvalidOperationException();
            }
        }

17. Example

Project: sharpmigrations
Source File: DataProvider.cs
View license
public virtual IDbConnection GetConnection() {
            return DbProviderFactory.CreateConnection();
        }

18. Example

View license
public static IDbConnection CreateConnection(string connectionString)
        {
            var connection = DbFactory.CreateConnection();
            connection.ConnectionString = connectionString;
            return connection;
        }

19. Example

View license
protected DbConnection CreateConnection(string connectionString)
        {
            connectionString = Check.EmptyCheck(connectionString);
            DbConnection connection = this.ProviderFactory.CreateConnection();
            connection.ConnectionString = connectionString;
            return connection;
        }

20. Example

Project: Glimpse.Nancy
Source File: ConnectionManager.cs
View license
public IDbConnection GetConnection()
        {
            var conn = this.factory.CreateConnection();
            conn.ConnectionString = @"Data Source=" + this.databaseName;
            conn.Open();
            return conn;
        }

21. Example

View license
protected virtual DbConnection GetDbConnection()
        {
            var connection = ProviderFactory.CreateConnection();
            if (connection == null)
            {
                throw new ApplicationException("Unable to create conneciton. Please make sure all DLL libraries have been installed.");
            }
            connection.ConnectionString = ConnectionString;
            connection.Open();
            return connection;
        }

22. Example

Project: orleans
Source File: DbConnectionFactory.cs
View license
public static DbConnection CreateConnection(string invariantName, string connectionString)
        {
            if (String.IsNullOrWhiteSpace(invariantName))
            {
                throw new ArgumentNullException(nameof(invariantName));
            }

            if (String.IsNullOrWhiteSpace(connectionString))
            {
                throw new ArgumentNullException(nameof(connectionString));
            }

            var factory = factoryCache.GetOrAdd(invariantName, GetFactory).Factory;
            var connection = factory.CreateConnection();

            if (connection == null)
            {
                throw new InvalidOperationException($"Database provider factory: '{invariantName}' did not return a connection object.");
            }

            connection.ConnectionString = connectionString;
            return connection;
        }

23. Example

Project: EDDiscovery
Source File: SQLiteConnectionED.cs
View license
private static bool DbFactoryWorks(DbProviderFactory factory)
        {
            if (factory != null)
            {
                try
                {
                    using (var conn = factory.CreateConnection())
                    {
                        conn.ConnectionString = "Data Source=:memory:;Pooling=true;";
                        conn.Open();
                        return true;
                    }
                }
                catch
                {
                }
            }

            return false;
        }

24. Example

Project: nesper
Source File: DbDriverGeneric.cs
View license
public override DbConnection CreateConnection()
        {
            try
            {
                DbConnection dbConnection = dbProviderFactory.CreateConnection();
                dbConnection.ConnectionString = ConnectionString;
                dbConnection.Open();
                return dbConnection;
            }
            catch (DbException ex)
            {
                String detail = "DbException: " + ex.Message + " VendorError: " + ex.ErrorCode;
                throw new DatabaseConfigException(
                    "Error obtaining database connection using connection-string '" + ConnectionString +
                    "' with detail " + detail, ex);
            }
        }

25. Example

Project: nesper
Source File: DbDriverMySQL.cs
View license
public override DbConnection CreateConnection()
        {
            DbConnection dbConnection = dbProviderFactory.CreateConnection();
            dbConnection.ConnectionString = ConnectionString;
            dbConnection.Open();
            return dbConnection;
        }

26. Example

Project: nesper
Source File: DbDriverGeneric.cs
View license
public override DbConnection CreateConnection()
        {
            try
            {
                DbConnection dbConnection = dbProviderFactory.CreateConnection();
                dbConnection.ConnectionString = ConnectionString;
                dbConnection.Open();
                return dbConnection;
            }
            catch (DbException ex)
            {
                String detail = "DbException: " + ex.Message + " VendorError: " + ex.ErrorCode;
                throw new DatabaseConfigException(
                    "Error obtaining database connection using connection-string '" + ConnectionString +
                    "' with detail " + detail, ex);
            }
        }

27. Example

Project: nesper
Source File: DbDriverMySQL.cs
View license
public override DbConnection CreateConnection()
        {
            DbConnection dbConnection = dbProviderFactory.CreateConnection();
            dbConnection.ConnectionString = ConnectionString;
            dbConnection.Open();
            return dbConnection;
        }

28. Example

Project: RawDataAccessBencher
Source File: Massive.cs
View license
public virtual DbConnection OpenConnection()
        {
            var result = _factory.CreateConnection();
            result.ConnectionString = ConnectionProfile.ConnectionString;
            result.Open();
            return result;
        }

29. Example

Project: RawDataAccessBencher
Source File: Massive.cs
View license
public virtual DbConnection OpenConnection()
		{
			var result = _factory.CreateConnection();
			result.ConnectionString = ConnectionString;
			result.Open();
			return result;
		}

30. Example

Project: Glimpse.Site
Source File: SqlFactory.cs
View license
public DbConnection CreateDbConnection(string connectionName)
        {
            var key = ConfigurationManager.AppSettings[connectionName];
            var connectionDetails = WebConfigurationManager.ConnectionStrings[key];

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

            var connection = factory.CreateConnection();
            connection.ConnectionString = connectionDetails.ConnectionString;

            return connection;
        }

31. Example

Project: Glimpse
Source File: GlimpseDbProviderFactory.cs
View license
public override DbConnection CreateConnection()
        {
            var connection = InnerFactory.CreateConnection();
            if (IsAdoMonitoringNeeded()) 
            {
                return new GlimpseDbConnection(connection, this);
            }
            return connection;
        }

32. Example

Project: waf
Source File: DbConnectionFactory.cs
View license
public static DbConnection CreateConnection(string connectionName)
        {
            var connectionStringSettings = ConfigurationManager.ConnectionStrings[connectionName];

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

            DbConnection connection = factory.CreateConnection();

            connection.ConnectionString = connectionStringSettings.ConnectionString;

            return connection;
        }

33. Example

Project: Lidarr
Source File: DataMapper.cs
View license
private DbCommand CreateNewCommand()
        {
            DbConnection conn = ProviderFactory.CreateConnection();
            conn.ConnectionString = ConnectionString;
            DbCommand cmd = conn.CreateCommand();
            SetSqlMode(cmd);
            return cmd;
        }

34. Example

Project: Lidarr
Source File: DirectDataMapper.cs
View license
private DbConnection OpenConnection()
        {
            var connection = _providerFactory.CreateConnection();
            connection.ConnectionString = _connectionString;
            connection.Open();
            return connection;
        }

35. Example

Project: sqlhelper2
Source File: ConnectionDatabase.cs
View license
private DbConnection CreateConnection() {
            var connection = _ProviderFactory.CreateConnection();
            connection.ConnectionString = _ConnectionString;
            connection.Open();
            return connection;
        }

36. Example

Project: sqlhelper2
Source File: Database.cs
View license
private DbConnection CreateConnection() {
            var connection = _ProviderFactory.CreateConnection();
            connection.ConnectionString = _ConnectionString;
            connection.Open();
            return connection;
        }

37. Example

View license
protected virtual DbConnection CreateConnection()
        {
            if (dbProviderFactory == null) {
                lock (lck) {
                    if (dbProviderFactory == null) {
                        var configDbConnString = ConfigurationManager.ConnectionStrings[dbConnStringName];
                        dbProviderFactory = DbProviderFactories.GetFactory(configDbConnString.ProviderName ?? "System.Data.SqlClient");
                    }
                }
            }
            var conn = dbProviderFactory.CreateConnection();
            conn.ConnectionString = dbConnString;

            return conn;
        }

38. Example

View license
protected virtual DbConnection CreateConnection()
        {
            if (dbProviderFactory == null)
            {
                lock (lck)
                {
                    if (dbProviderFactory == null)
                    {
                        var configDbConnString = ConfigurationManager.ConnectionStrings[dbConnStringName];
                        dbProviderFactory = DbProviderFactories.GetFactory(configDbConnString.ProviderName ?? "System.Data.SqlClient");
                    }
                }
            }
            var conn = dbProviderFactory.CreateConnection();
            conn.ConnectionString = dbConnString;

            return conn;
        }

39. Example

View license
public void Dispose()
        {
            using (var conn = dbProviderFactory.CreateConnection()) {
                conn.Open();

                conn.Execute("delete from Applications where Path = @path", new { path });
                conn.Execute("delete from ApplicationConfigs where Path = @path", new { path });
                conn.Execute("delete from Globals where ConfKey = @confKey", new { confkey });
            }
        }

40. Example

View license
public void Dispose()
        {
            using (var conn = dbProviderFactory.CreateConnection()) {
                conn.Open();

                conn.Execute("delete from Users where Id = @userId", new { userId });
                conn.Execute("delete from UserClaims where UserId = @userId", new { userId });
            }
        }

41. Example

View license
public void Dispose()
        {
            using (var conn = dbProviderFactory.CreateConnection()) {
                conn.Open();

                conn.Execute("delete from Applications where Path = @path", new { path });
                conn.Execute("delete from ApplicationConfigs where Path = @path", new { path });
                conn.Execute("delete from Globals where ConfKey = @confKey", new { confkey });
            }
        }

42. Example

View license
public void Dispose()
        {
            using (var conn = dbProviderFactory.CreateConnection()) {
                conn.Open();

                conn.Execute("delete from Users where Id = @userId", new { userId });
                conn.Execute("delete from UserClaims where UserId = @userId", new { userId });
            }
        }

43. Example

Project: DbExtensions
Source File: Database.cs
View license
static IDbConnection CreateConnection(string connectionString, string callerProviderInvariantName, out string providerInvariantName) {

         connectionString = connectionString ?? DatabaseConfiguration.DefaultConnectionString;
         providerInvariantName = callerProviderInvariantName ?? DatabaseConfiguration.DefaultProviderInvariantName;

         if (connectionString == null) {
            throw new InvalidOperationException($"A default connection string name must be specified in the {typeof(DatabaseConfiguration).FullName}.{nameof(DatabaseConfiguration.DefaultConnectionString)} property.");
         }

         if (providerInvariantName == null) {
            throw new InvalidOperationException($"A default provider name must be specified in the {typeof(DatabaseConfiguration).FullName}.{nameof(DatabaseConfiguration.DefaultProviderInvariantName)} property.");
         }

         DbProviderFactory factory = GetProviderFactory(providerInvariantName);

         IDbConnection connection = factory.CreateConnection();
         connection.ConnectionString = connectionString;

         return connection;
      }

44. Example

Project: ReliableDbProvider
Source File: DbTestBase.cs
View license
protected virtual Context GetContext()
        {
            var provider = GetProvider();
            var connection = provider.CreateConnection();
            connection.ConnectionString = ConnectionString;
            return new Context(connection);
        }

45. Example

Project: ReliableDbProvider
Source File: Massive.cs
View license
public virtual DbConnection OpenConnection()
        {
            var result = _factory.CreateConnection();
            result.ConnectionString = ConnectionString;
            result.Open();
            return result;
        }

46. Example

Project: NServiceKit.OrmLite
Source File: Massive.cs
View license
public virtual DbConnection OpenConnection()
        {
            var result = _factory.CreateConnection();
            result.ConnectionString = _connectionString;
            result.Open();
            return result;
        }

47. Example

View license
static DbConnection CreateConnection()
        {
            return DbConfiguration.DependencyResolver.GetService<DbProviderFactory>(NuoDbProviderServices.ProviderInvariantName).CreateConnection();
        }

48. Example

Project: NZBDash
Source File: DBConfiguration.cs
View license
public virtual IDbConnection DbConnection()
        {
            var fact = Factory.CreateConnection();
            if (fact == null)
            {
                throw new Exception("Factory returned null");
            }
            fact.ConnectionString = "Data Source=" + DbFile();
            return fact;
        }

49. Example

View license
public static DbConnection CreateConnection(string invariantName, string connectionString)
        {
            if (String.IsNullOrWhiteSpace(invariantName))
            {
                throw new ArgumentNullException(nameof(invariantName));
            }

            if (String.IsNullOrWhiteSpace(connectionString))
            {
                throw new ArgumentNullException(nameof(connectionString));
            }

            var factory = factoryCache.GetOrAdd(invariantName, GetFactory).Factory;
            var connection = factory.CreateConnection();

            if (connection == null)
            {
                throw new InvalidOperationException($"Database provider factory: '{invariantName}' did not return a connection object.");
            }

            connection.ConnectionString = connectionString;
            return connection;
        }

50. Example

Project: Radarr
Source File: DataMapper.cs
View license
private DbCommand CreateNewCommand()
        {
            DbConnection conn = ProviderFactory.CreateConnection();
            conn.ConnectionString = ConnectionString;
            DbCommand cmd = conn.CreateCommand();
            SetSqlMode(cmd);
            return cmd;
        }