How do I distinguish between a service name and a connect descriptor in a connection string?

723 views Asked by At

Hopefully, this should be an easy one for the Oracle bods.

So, further to my previous Question, I now need to be able to process a connection string in C# and decide whether to perform an LDAP lookup on the 'Data Source' value (if it is a service name), or just take it as it is (a connect descriptor). What is the best and most definitive way of doing this? I don't want to be doing wishy-washy things like checking if the first character is an open parenthesis. I'm looking for a specific pattern/signature to identify if a 'Data Source' is a service name or connect descriptor.

For example (as obtained here), with a service name, it might be this:

Data Source=TORCL;User Id=myUsername;Password=myPassword;

With a connect descriptor, it might be this:

Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=MyOracleSID)));User Id=myUsername; Password=myPassword;

Thanks.

1

There are 1 answers

0
Neo On

In the absence of an answer, I devised my own solution which isn't complicated and I've assumed that a connect descriptor will always contain "DESCRIPTION". If this assumption is correct, the solution is correct. If not, then please feel free to suggest your own...

string dataSource = connectionString.Split(';').Select(x => x.Split('=')).Single(x => x.First() == "Data Source").Last();
bool isConnectDescriptor = dataSource.IndexOf("DESCRIPTION", StringComparison.OrdinalIgnoreCase) >= 0;