views:

9

answers:

1

I'm using a SqlConnectionStringBuilder instance to parse a connection string, but don't want to check its key names for validity. By behaviour the builder will throw an exception if an unsupported key is encountered in the string.

For example, exception on unknown key "whatever" is:

Keyword not supported: 'whatever'.

What I want to do is have an entire connection string parsed without exception, despite unsupported keywords.

Without writing code to perform this trick, is there native support for just the parsing aspect in the .NET Framework, or can I hook into what's already internalized in the connection builder class in some fashion?

+1  A: 

You could use the underlying DbConnectionStringBuilder class which does not validate its keys.

Developers can create connection strings using either a strongly typed connection string builder class, or they can use the DbConnectionStringBuilder class. The DbConnectionStringBuilder performs no checks for valid key/value pairs. Therefore, it is possible using this class to create invalid connection strings. The SqlConnectionStringBuilder supports only key/value pairs that are supported by SQL Server; trying to add invalid pairs will throw an exception.

Steve Townsend
Awesome. Thanks!
John K