SqlConnectionFactory Class

Definition

Instances of this class are used to create DbConnection objects for SQL Server based on a given database name or connection string. By default, the connection is made to '.\SQLEXPRESS'. This can be changed by changing the base connection string when constructing a factory instance.

public sealed class SqlConnectionFactory : System.Data.Entity.Infrastructure.IDbConnectionFactory
type SqlConnectionFactory = class
    interface IDbConnectionFactory
Public NotInheritable Class SqlConnectionFactory
Implements IDbConnectionFactory
Inheritance
SqlConnectionFactory
Implements

Remarks

An instance of this class can be set on the Database class to cause all DbContexts created with no connection information or just a database name or connection string to use SQL Server by default. This class is immutable since multiple threads may access instances simultaneously when creating connections.

Constructors

SqlConnectionFactory()

Creates a new connection factory with a default BaseConnectionString property of 'Data Source=.\SQLEXPRESS; Integrated Security=True; MultipleActiveResultSets=True;'.

SqlConnectionFactory(String)

Creates a new connection factory with the given BaseConnectionString property.

Properties

BaseConnectionString

The connection string to use for options to the database other than the 'Initial Catalog'. The 'Initial Catalog' will be prepended to this string based on the database name when CreateConnection is called. The default is 'Data Source=.\SQLEXPRESS; Integrated Security=True;'.

Methods

CreateConnection(String)

Creates a connection for SQL Server based on the given database name or connection string. If the given string contains an '=' character then it is treated as a full connection string, otherwise it is treated as a database name only.

Applies to