Here is my string line:
string conSTR = "Data Source=(local);Initial Catalog=MyDB;User ID=sa";
I just want to get the string "(local)"
, and "MyDb"
and "sa"
word anybody can suggest how to do it in C#.
Here is my string line:
string conSTR = "Data Source=(local);Initial Catalog=MyDB;User ID=sa";
I just want to get the string "(local)"
, and "MyDb"
and "sa"
word anybody can suggest how to do it in C#.
Assuming this is actually a SQL connection string, you could use SqlConnectionStringBuilder
- pass the string into the constructor, then interrogate the appropriate properties.
Use a SqlConnectionStringBuilder
:
var builder = new SqlConnectionStringBuilder(conSTR);
Then you can read the builder's properties, like .DataSource
, .UserID
and .Password
.