سؤال

Hi Can anyone help me with a Regular expression to extract the value of Initial Catalog from a Connection String ?

  'Data Source=server\instance;Initial Catalog=MyDatabase;Integrated Security=True'

I want to extract 'MyDatabase' from the connection string

   Catalog=(?s)(.*); 

Using above mentioned Expression. I want only the Database name. How can i make it ignore Catalog and ; at the end and any possible blank spaces

هل كانت مفيدة؟

المحلول

An SSIS Expression you can use in another variable to extract the Initial Catalog name.

SUBSTRING ( 
    SUBSTRING (  
        @[User:Connstring], 
        FINDSTRING (  
            @[User:Connstring],
            "Initial Catalog=",
            1),
        LEN (  @[User:Connstring])
    ),
    17,
    FINDSTRING ( 
        SUBSTRING (  
            @[User:Connstring],
            FINDSTRING (
                @[User:Connstring],
                "Initial Catalog=",
                1
            ),
            LEN ( @[User:Connstring])
        ),
        ";",
        1
    )  
    - 17
)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top