Powershell 2.0 and Sql server 2005 help

Tagged: , , ,

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Dustin Ayers Dustin Ayers 2 years, 10 months ago.

  • Author
    Posts
  • #16207
    Profile photo of Dustin Ayers
    Dustin Ayers
    Participant

    I am trying to figure out a way using either powershell or command line to confirm that as data base is online after I started the Database service?

    I find some commands out there but they don't seem to do what I need to do. I have very limited SQL experience.

  • #16209
    Profile photo of Joakim
    Joakim
    Participant

    It all depends on how you want to Connect etc. But this is an outline of how you could do it:

    $connectionString = "connectionstring" 
    #open database connection to SQL Server
    
    $conn = New-Object system.Data.SqlClient.SqlConnection
    $conn.connectionstring = $connectionString
    $conn.open()
    
    switch ($conn.State)
    {
    
      "Open" {  Write-OutPut "Do some work"; }
    
      Default { Write-OutPut "The connection is $($conn.State).  There has been an error connecting to the database."; }
    }
    
    
    
  • #16256
    Profile photo of Dustin Ayers
    Dustin Ayers
    Participant

    Thank you very much Joakim. I will try this and report back.

You must be logged in to reply to this topic.