public string RetrieveDataSource
{
get
SqlConnection sqlConnection = new SqlConnection(this.CurrentConnectionString);
SqlCommand sqlCmd = new SqlCommand();
sqlConnection.Open();
sqlCmd.Connection = sqlConnection;
return "Server Name :" + sqlCmd.Connection.DataSource;
}
The above code returns the DataSource in the following format “MyServerName\SQLInstanceName”
Is there any other way we can achieve the same result? The CurrentConnectionString comes from a web.config file. I'm trying to improve the code.
Thanks!