0

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.

Community
  • 1
  • 1
Neo
  • 4,145
  • 6
  • 53
  • 76
  • these connect strings are part of your web.config (or app.config), right? If your company uses ldap in place of tnsnames, I would assume you'd just look up each one needed (option 1) – tbone Jan 30 '13 at 10:35
  • Sure, but I the .config could specify a connect descriptor explicitly in exceptional circumstances, and I just want to write my code so that it will handle such cases. – Neo Jan 30 '13 at 10:53
  • but YOU control that config, so you know which oddball cases you specify the full connect string, no? – tbone Jan 30 '13 at 12:20
  • No. Not necessarily. The knowledge of what connection strings might be passed into my generic function is irrelevant. I can't write code that caters for known service names and connect descriptors containing certain strings. I need a general rule for differentiating between a service name and a connect descriptor regardless of where it came from. The .config might change under my feet - I don't want code elsewhere breaking because of that. – Neo Jan 30 '13 at 14:09

1 Answers1

0

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;
Neo
  • 4,145
  • 6
  • 53
  • 76