Ejemplo n.º 1
0
        /// <summary>
        /// Creates an instance of <see cref="DbConnection"/> that can be used to connect to the SQL LocalDB instance
        /// using the only connection string configured in the current application configuration file.
        /// </summary>
        /// <param name="instance">The <see cref="ISqlLocalDbInstance"/> to get the connection string builder for.</param>
        /// <returns>
        /// The created instance of <see cref="DbConnectionStringBuilder"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="instance"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// No connection strings are configured in the application configuration file or more than one
        /// connection string is configured in the application configuration file.
        /// </exception>
        /// <remarks>
        /// Connection strings may be inherited from outside the current application's configuration file, such as from
        /// <c>machine.config</c>.  To use this overload it is recommended that, unless otherwise needed, a <c>&lt;clear/&gt;</c>
        /// element is added to the <c>&lt;connectionStrings&gt;</c> section of your application configuration file to
        /// prevent the default connection strings from being inherited.
        /// </remarks>
        public static DbConnection GetConnectionForDefaultModel(this ISqlLocalDbInstance instance)
        {
            DbConnectionStringBuilder builder = instance.GetConnectionStringForDefaultModel();

            return(CreateConnection(builder.ConnectionString));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates an instance of <see cref="DbConnectionStringBuilder"/> that can be used to connect to the SQL LocalDB instance
 /// using the only connection string configured in the current application configuration file.
 /// </summary>
 /// <param name="instance">The <see cref="ISqlLocalDbInstance"/> to get the connection string builder for.</param>
 /// <returns>
 /// The created instance of <see cref="DbConnectionStringBuilder"/>.
 /// </returns>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="instance"/> is <see langword="null"/>.
 /// </exception>
 /// <exception cref="InvalidOperationException">
 /// No connection strings are configured in the application configuration file or more than one
 /// connection string is configured in the application configuration file.
 /// </exception>
 /// <remarks>
 /// Connection strings may be inherited from outside the current application's configuration file, such as from
 /// <c>machine.config</c>.  To use this overload it is recommended that, unless otherwise needed, a <c>&lt;clear/&gt;</c>
 /// element is added to the <c>&lt;connectionStrings&gt;</c> section of your application configuration file to
 /// prevent the default connection strings from being inherited.
 /// </remarks>
 public static DbConnectionStringBuilder GetConnectionStringForDefaultModel(this ISqlLocalDbInstance instance) => instance.GetConnectionStringForDefaultModel(null);