Powershell 2.0 and Sql server 2005 help

This topic contains 2 replies, has 2 voices, and was last updated by  Dustin Ayers 4 years, 1 month ago.

  • Author
  • #16207

    Dustin Ayers

    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


    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
    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

    Dustin Ayers

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

You must be logged in to reply to this topic.