none
Database Server Exisits or not RRS feed

Answers

  • Well, you can use the .NET Framework factory classes to poll the Intranet for all instances of SQL Server who have SQL Browser service running. That is, if the server's administrator wants the server to be visible to the Intranet they enable the protocols and start the SQL Browser. The factory classes can request each Browser to report all instances and their state (running, paused, stopped). I wrote an example application for my 7th edition that illustrates how these factory classes could be coded. Here is a snippet of that application that might get you started. Yes, it's in VB.NET--you'll have to deal with the differences.

    In this example, I've already pulled up a list of providers and I've chosen "SqlClient Data Provider" from the list and passed it to the ShowInstance function.

    Private Sub ShowInstance(ByVal drProvider As DataRow)
            Try
                Me.Cursor = Cursors.WaitCursor
                Dim factory As DbProviderFactory = DbProviderFactories.GetFactory(drProvider)
                Dim dsE As DbDataSourceEnumerator = factory.CreateDataSourceEnumerator()
                If dsE Is Nothing Then
                    DataGridView1.DataSource = Nothing
                    MsgBox("No instances visible for this provider(" & drProvider(0).ToString & ")")
                Else
                    DataGridView1.DataSource = dsE.GetDataSources()
                End If
            Catch exNS As NotSupportedException
                MsgBox("This provider does not support data source enumeration...")
            Catch exCE As System.Configuration.ConfigurationException
                MsgBox("The " & drProvider(0).ToString & " could not be loaded.")
            Finally
                Me.Cursor = Cursors.Default
            End Try
    
        End Sub

    __________________________________________________________________
    William Vaughn
    Mentor, Consultant, Trainer, MVP
    http://betav.com
    http://betav.com/blog/billva
    http://www.hitchhikerguides.net

    “Hitchhiker’s Guide to Visual Studio and SQL Server (7th Edition)”

    Please click the Mark as Answer button if a post solves your problem!

    Thursday, April 1, 2010 6:05 PM
    Moderator

All replies

  • Well, you can use the .NET Framework factory classes to poll the Intranet for all instances of SQL Server who have SQL Browser service running. That is, if the server's administrator wants the server to be visible to the Intranet they enable the protocols and start the SQL Browser. The factory classes can request each Browser to report all instances and their state (running, paused, stopped). I wrote an example application for my 7th edition that illustrates how these factory classes could be coded. Here is a snippet of that application that might get you started. Yes, it's in VB.NET--you'll have to deal with the differences.

    In this example, I've already pulled up a list of providers and I've chosen "SqlClient Data Provider" from the list and passed it to the ShowInstance function.

    Private Sub ShowInstance(ByVal drProvider As DataRow)
            Try
                Me.Cursor = Cursors.WaitCursor
                Dim factory As DbProviderFactory = DbProviderFactories.GetFactory(drProvider)
                Dim dsE As DbDataSourceEnumerator = factory.CreateDataSourceEnumerator()
                If dsE Is Nothing Then
                    DataGridView1.DataSource = Nothing
                    MsgBox("No instances visible for this provider(" & drProvider(0).ToString & ")")
                Else
                    DataGridView1.DataSource = dsE.GetDataSources()
                End If
            Catch exNS As NotSupportedException
                MsgBox("This provider does not support data source enumeration...")
            Catch exCE As System.Configuration.ConfigurationException
                MsgBox("The " & drProvider(0).ToString & " could not be loaded.")
            Finally
                Me.Cursor = Cursors.Default
            End Try
    
        End Sub

    __________________________________________________________________
    William Vaughn
    Mentor, Consultant, Trainer, MVP
    http://betav.com
    http://betav.com/blog/billva
    http://www.hitchhikerguides.net

    “Hitchhiker’s Guide to Visual Studio and SQL Server (7th Edition)”

    Please click the Mark as Answer button if a post solves your problem!

    Thursday, April 1, 2010 6:05 PM
    Moderator
  • If it's SQL Server then the best option would be to use SQL Server SMO library. Following example shouws you how to use SMO in .NET

    http://msdn.microsoft.com/en-us/magazine/cc163409.aspx


    Val Mazur (MVP) http://www.xporttools.net
    Monday, April 5, 2010 10:35 AM
    Moderator