Getting the server name and SQL instance name [modified]
-
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 Solution:
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; } }
Conclusion: The above code returns the DataSource in the following format “MyServerName\SQLInstanceName”Swetha
modified on Tuesday, April 28, 2009 3:49 PM
-
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 Solution:
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; } }
Conclusion: The above code returns the DataSource in the following format “MyServerName\SQLInstanceName”Swetha
modified on Tuesday, April 28, 2009 3:49 PM
-
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 Solution:
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; } }
Conclusion: The above code returns the DataSource in the following format “MyServerName\SQLInstanceName”Swetha
modified on Tuesday, April 28, 2009 3:49 PM
I think the Articles section is a better place for this post... This is a forum: questions>answers... Therefore, if you already have the connection string(this.CurrentConnectionString), why make all coding just to extract the server name??? :~