Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Getting the server name and SQL instance name [modified]

Getting the server name and SQL instance name [modified]

Scheduled Pinned Locked Moved C#
csharpasp-netdatabasesysadmin
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    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

    J R 2 Replies Last reply
    0
    • L Lost User

      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

      J Offline
      J Offline
      Jimmanuel
      wrote on last edited by
      #2

      is there a question in there or is this an FYI post?

      :Badger:

      1 Reply Last reply
      0
      • L Lost User

        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

        R Offline
        R Offline
        Rolando CC
        wrote on last edited by
        #3

        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??? :~

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups