Get the Server name and SQL instance name in ToolPart (c#)

Requirement: ServerName and InstanceName to be displayed in a ToolPart

Data: The classes required to retrieve the DataSource(this contains the server name and instance name used in the connection string) using ASP.NET are,

SqlConnection, SqlCommand


public string RetrieveDataSource




SqlConnection sqlConnection = new SqlConnection(this.CurrentConnectionString); SqlCommand sqlCmd = new SqlCommand(); sqlConnection.Open();

sqlCmd.Connection = sqlConnection; return “Server Name :” + sqlCmd.Connection.DataSource;



Conclusion: The above code returns the DataSource in the following format “MyServerName\SQLInstanceName”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s