.net - Is there any connection string parser in C#? -
i have connection string , want able peek out example "data source". there parser, or have search string?
yes, there's system.data.common.dbconnectionstringbuilder
class.
the dbconnectionstringbuilder class provides base class typed connection string builders (sqlconnectionstringbuilder, oledbconnectionstringbuilder, , on) derive. connection string builders let developers programmatically create syntactically correct connection strings, , parse , rebuild existing connection strings.
the subclasses of interest are:
system.data.entityclient.entityconnectionstringbuilder system.data.odbc.odbcconnectionstringbuilder system.data.oledb.oledbconnectionstringbuilder system.data.oracleclient.oracleconnectionstringbuilder system.data.sqlclient.sqlconnectionstringbuilder
for example, "peek out data source" sql-server connection string, can do:
var builder = new sqlconnectionstringbuilder(connectionstring); var datasource = builder.datasource;
Comments
Post a Comment