If you already have the connection string, just split the string like so:
string[] parts = connectionString.Split(';');
and then iterate through the
parts
array until you find the part that starts with "Data Source=".
string dataSource = "";
for (int i =0; i < parts.Length; i++)
{
string part = parts[i].Trim();
if (part.StartsWith("Data Source="))
{
dataSource = part.Replace("Data Source=", "");
break;
}
}
It ain't rocket science...