src/Shared/EntityFramework/Infrastructure/SqlCeConnectionFactory.cs
/// <summary>
/// Creates a connection for SQL Server Compact Edition 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.
/// </summary>
/// <param name="nameOrConnectionString"> The database name or connection string. </param>
/// <returns> An initialized DbConnection. </returns>
Creates a connection for SQL Server Compact Edition 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.
Creates a connection for SQL Server Compact Edition 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 .
public DbConnection CreateConnection(string nameOrConnectionString)
        {
            Check.NotEmpty(nameOrConnectionString, "nameOrConnectionString");
            var factory = DbConfiguration.DependencyResolver.GetService<DbProviderFactory>(ProviderInvariantName);
            Debug.Assert(factory != null, "Expected DbProviderFactories.GetFactory to throw if provider not found.");
            var connection = factory.CreateConnection();
            if (connection == null)
            {
                throw Error.DbContext_ProviderReturnedNullConnection();
            }
            string connectionString;
            if (DbHelpers.TreatAsConnectionString(nameOrConnectionString))
            {
                connectionString = nameOrConnectionString;
            }
            else
            {
                if (!nameOrConnectionString.EndsWith(".sdf", ignoreCase: true, culture: null))
                {
                    nameOrConnectionString += ".sdf";
                }
                var dataPath = (DatabaseDirectory.StartsWith("|", StringComparison.Ordinal)
                                && DatabaseDirectory.EndsWith("|", StringComparison.Ordinal))
                                   ? DatabaseDirectory + nameOrConnectionString
                                   : Path.Combine(DatabaseDirectory, nameOrConnectionString);
                connectionString = String.Format(CultureInfo.InvariantCulture, "Data Source={0}; {1}", dataPath, BaseConnectionString);
            }
            DbInterception.Dispatch.Connection.SetConnectionString(
                connection,
                new DbConnectionPropertyInterceptionContext<string>().WithValue(connectionString));
            return connection;
        }
public DbConnection CreateConnection ( string nameOrConnectionString ) { Check . NotEmpty ( nameOrConnectionString , " " ) ; var factory = DbConfiguration . DependencyResolver . GetService < DbProviderFactory > ( ProviderInvariantName ) ; Debug . Assert ( factory != null , " " ) ; var connection = factory . CreateConnection ( ) ; if ( connection == null ) { throw Error . DbContext_ProviderReturnedNullConnection ( ) ; } string connectionString ; if ( DbHelpers . TreatAsConnectionString ( nameOrConnectionString ) ) { connectionString = nameOrConnectionString ; } else { if ( ! nameOrConnectionString . EndsWith ( " " , ignoreCase : true , culture : null ) ) { nameOrConnectionString += " " ; } var dataPath = ( DatabaseDirectory . StartsWith ( " " , StringComparison . Ordinal ) && DatabaseDirectory . EndsWith ( " " , StringComparison . Ordinal ) ) ? DatabaseDirectory + nameOrConnectionString : Path . Combine ( DatabaseDirectory , nameOrConnectionString ) ; connectionString = String . Format ( CultureInfo . InvariantCulture , " " , dataPath , BaseConnectionString ) ; } DbInterception . Dispatch . Connection . SetConnectionString ( connection , new DbConnectionPropertyInterceptionContext < string > ( ) . WithValue ( connectionString ) ) ; return connection ; }
Creates a connection for SQL Server Compact Edition based on the given database name or connection string.
Creates a connection for SQL Server Compact Edition based on the given database name or connection string .
An initialized DbConnection.
An initialized DbConnection .
nameOrConnectionString
string
The database name or connection string.
The database name or connection string .