Example #1
0
        /// <summary>
        /// Sets the physical database file name in the specified <see cref="DbConnectionStringBuilder"/>.
        /// </summary>
        /// <param name="value">The <see cref="DbConnectionStringBuilder"/> to set the physical database file name for.</param>
        /// <param name="fileName">The physical file name to set.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="value"/> is <see langword="null"/> or invalid.
        /// </exception>
        /// <exception cref="NotSupportedException">
        /// <paramref name="fileName"/> references the Data Directory for the current <see cref="AppDomain"/> but
        /// the Data Directory for the current <see cref="AppDomain"/> has no value set.
        /// </exception>
        public static void SetPhysicalFileName(this DbConnectionStringBuilder value, string fileName)
        {
            string fullPath = null;

            if (fileName != null)
            {
                fullPath = ExpandDataDirectoryIfPresent(fileName);

                try
                {
                    // Only full file paths are supported, so ensure that the path is fully qualified before it is set
                    fullPath = Path.GetFullPath(fullPath);
                }
                catch (ArgumentException ex)
                {
                    throw new ArgumentException(SRHelper.Format(SR.Extensions_InvalidPathFormat, ex.Message), nameof(fileName), ex);
                }
                catch (NotSupportedException ex)
                {
                    throw new ArgumentException(SRHelper.Format(SR.Extensions_InvalidPathFormat, ex.Message), nameof(fileName), ex);
                }
            }

            value.SetKeywordValueAsString(AttachDBFilenameKeywordName, fullPath);
        }
Example #2
0
 /// <summary>
 /// Sets the Initial Catalog name in the specified <see cref="DbConnectionStringBuilder"/>.
 /// </summary>
 /// <param name="value">The <see cref="DbConnectionStringBuilder"/> to set the Initial Catalog name for.</param>
 /// <param name="initialCatalog">The name of the Initial Catalog to set.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="value"/> is <see langword="null"/>.
 /// </exception>
 public static void SetInitialCatalogName(this DbConnectionStringBuilder value, string initialCatalog)
 {
     value.SetKeywordValueAsString(InitialCatalogKeywordName, initialCatalog);
 }