chenge c# code to:
if config.txt file is exist
config contain:
server=serverip\mssqlserver instant name
:
 connectionString = server



below code:


using System;
using System.Data.SqlClient;

class Program
{
    static void Main(string[] args)
    {
        string connectionString = @"Server=(local)\MSSQL2022;Integrated Security=True;";
        string loginName = "Salary";
        string password = "salary";

        try
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();

                // Create Login if it does not exist
                CreateLogin(connection, loginName, password);

                // Get all databases that start with "Region"
                var databases = GetRegionDatabases(connection);

                foreach (var dbName in databases)
                {
                    CreateUserAndAssignRoles(connection, dbName, loginName);
                }

                Console.WriteLine("User creation and role assignment completed successfully.");
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine("An error occurred: " + ex.Message);
        }
    }

    private static void CreateLogin(SqlConnection connection, string loginName, string password)
    {
        string createLoginSql =
            "IF NOT EXISTS (SELECT * FROM sys.server_principals WHERE name = @LoginName) " +
            "BEGIN " +
            "DECLARE @SQL NVARCHAR(MAX); " +
            "SET @SQL = 'CREATE LOGIN [' + @LoginName + '] WITH PASSWORD = ''' + @Password + ''';'; " +
            "EXEC sp_executesql @SQL; " +
            "ALTER SERVER ROLE [bulkadmin] ADD MEMBER [" + loginName + "]; " +
            "ALTER SERVER ROLE [diskadmin] ADD MEMBER [" + loginName + "]; " +
            "END";

        using (SqlCommand command = new SqlCommand(createLoginSql, connection))
        {
            command.Parameters.AddWithValue("@LoginName", loginName);
            command.Parameters.AddWithValue("@Password", password);
            command.ExecuteNonQuery();
        }
    }
    
    private static string[] GetRegionDatabases(SqlConnection connection)
    {
        string query = "SELECT name FROM sys.databases WHERE name LIKE 'Region%'";
        using (SqlCommand command = new SqlCommand(query, connection))
        using (SqlDataReader reader = command.ExecuteReader())
        {
            var databases = new System.Collections.Generic.List<string>();
            while (reader.Read())
            {
                databases.Add(reader.GetString(0));
            }
            return databases.ToArray();
        }
    }

    private static void CreateUserAndAssignRoles(SqlConnection connection, string dbName, string loginName)
    {
        Console.WriteLine("Current Database is: " + dbName);
        
        // Use a new SqlConnection for the specific database context
        using (SqlConnection dbConnection = new SqlConnection(connection.ConnectionString + ";Database=" + dbName))
        {
            dbConnection.Open();

            // Check if the user exists and drop if it does
            string dropUserSql = 
                "IF EXISTS (SELECT * FROM sys.database_principals WHERE name = @LoginName) " +
                "BEGIN " +
                "DROP USER [" + loginName + "]; " +
                "END";

            using (SqlCommand command = new SqlCommand(dropUserSql, dbConnection))
            {
                command.Parameters.AddWithValue("@LoginName", loginName);
                command.ExecuteNonQuery();
            }

            // Create user and assign roles
            string createUserSql = 
                "CREATE USER [" + loginName + "] FOR LOGIN [" + loginName + "]; " +
                "ALTER USER [" + loginName + "] WITH DEFAULT_SCHEMA=[dbo]; " +
                "ALTER ROLE [db_accessadmin] ADD MEMBER [" + loginName + "]; " +
                "ALTER ROLE [db_datareader] ADD MEMBER [" + loginName + "]; " +
                "ALTER ROLE [db_datawriter] ADD MEMBER [" + loginName + "]; " +
                "ALTER ROLE [db_ddladmin] ADD MEMBER [" + loginName + "]; " +
                "ALTER ROLE [db_owner] ADD MEMBER [" + loginName + "];";

            using (SqlCommand command = new SqlCommand(createUserSql, dbConnection))
            {
                command.ExecuteNonQuery();
            }
        }
    }
}