How to get application name from SQL Server connection string or IIS application name using C #?

How to get application name from SQL Server connection string in web.config file.

I want to use to log escalated error messages from a web application to the Windows event log.

Maybe there is a better way to do this, i.e. use the name of the IIS / web application?

thanks

Mark

+4
source share
2 answers

What does the connection string look like?

DbConnectionStringBuilder is good for parsing and checking connection string values ​​by key:

  DbConnectionStringBuilder db = new DbConnectionStringBuilder(); db.ConnectionString = connectionString; Console.WriteLine(db["Application Name"]); 

otherwise, you can get various details from http server variables .

+3
source

SqlConnectionStringBuilder is also useful if you are using SQL Server:

 SqlConnectionStringBuilder sc = new SqlConnectionStringBuilder(connectionString); string applicationName = sc.ApplicationName; 
+1
source

All Articles