AzurePoolCrossDbGenerator/DbAccess.cs
/// <summary>
/// Get the DB name from the full connection string using regex
/// </summary>
/// <param name="dbConnectionString"></param>
/// <returns></returns>
Get the DB name from the full connection string using regex
Get the DB name from the full connection string using regex
public static string GetDbNameFromConnectionString(string dbConnectionString)
        {
            string regexPattern = @"Initial Catalog\s*=\s*([^;\s]+)";
            var regexOptions = RegexOptions.IgnoreCase;
            Match match = Regex.Match(dbConnectionString, regexPattern, regexOptions);
            if (!match.Success || match.Groups.Count<2 || string.IsNullOrEmpty(match.Groups[1].Value))
            {
                Program.WriteLine();
                Program.WriteLine("Cannot extract DB name from the connection string.", ConsoleColor.Red);
                Program.ExitApp();
            }
            return match.Groups[1].Value;
        }
public static string GetDbNameFromConnectionString ( string dbConnectionString ) { string regexPattern = @"Initial Catalog\s*=\s*([^;\s]+)" ; var regexOptions = RegexOptions . IgnoreCase ; Match match = Regex . Match ( dbConnectionString , regexPattern , regexOptions ) ; if ( ! match . Success || match . Groups . Count < 2 || string . IsNullOrEmpty ( match . Groups [ 1 ] . Value ) ) { Program . WriteLine ( ) ; Program . WriteLine ( " " , ConsoleColor . Red ) ; Program . ExitApp ( ) ; } return match . Groups [ 1 ] . Value ; }
Get the DB name from the full connection string using regex
Get the DB name from the full connection string using regex
None
dbConnectionString
string
None