How to get list of connection string keywords available in sqlclie

  • Thread starter Thread starter Guest
  • Start date Start date
Hi Armin,

It seems that I can get the list from an instance of
System.Data.SqlClient.ConnectionStringBuilder. Not sure how to get it yet
since I'm not familiar of collections.
 
Peter said:
Hi Armin,

It seems that I can get the list from an instance of
System.Data.SqlClient.ConnectionStringBuilder. Not sure how to get
it yet since I'm not familiar of collections.


I didn't think of this class as being a collection like data source, more I
pointed to it because you can browse the available properties/keywords and
explicitly set them "early bound" without the need to fill the values into a
connection string. Though, I had a closer look at it, finding that it
implements IEnumerable, so you can use For Each:

Dim sb As New System.Data.SqlClient.SqlConnectionStringBuilder

sb.ConnectTimeout = 17
sb.DataSource = "test"

For Each pair As KeyValuePair(Of String, Object) In sb
'access the Key and Value propertis of object 'pair'
Next

May I ask why you need this?

Armin
 
Thanks Armin. I'm thinking about providing administrator of an application
the ability to set some of those keywords and then build the connection
string dynamcially. I can hardcode them instead of retrieving them
programmatically.
I wonder whether those keywords will expand automatically when the
underlying sqlclient provider support more keywords.

Using your sample coding will only fetch those keywords which have values
assigned. If I want to get all the keywords, I need to go thru the
keys.syncroot array and I don't think I can use KeyValuePair to loop thru
them.

Peter
 
Peter said:
Thanks Armin. I'm thinking about providing administrator of an
application the ability to set some of those keywords and then build
the connection string dynamcially. I can hardcode them instead of
retrieving them programmatically.
I wonder whether those keywords will expand automatically when the
underlying sqlclient provider support more keywords.

Using your sample coding will only fetch those keywords which have
values assigned. If I want to get all the keywords, I need to go
thru the keys.syncroot array and I don't think I can use
KeyValuePair to loop thru them.

Why don't you put all possible keywords into a list? Has to be done once
only.


Armin
 
Back
Top