Test if it is indeed a SQL Server behind a port

This topic contains 2 replies, has 2 voices, and was last updated by  Kamil 1 month ago.

  • Author
    Posts
  • #99309

    Kamil
    Participant

    Good day.
    My PS 5.1 script tests a connection with a SQL Server. The script does it step by step:
    1 Ping the server with the Test-Connection
    2 Probe if the port is open with the System.Net.TcpClient.Connect()
    3 Now, here i would like to know, without sending credential, if it is indeed a SQL Server behind the port. Is it possible?

    Regards
    Kamil

  • #99312

    iain Barnetson
    Participant

    If you're checking by name, you could use

    $ConnectionString = "data source = server,55272; initial catalog = master; trusted_connection = true;"
    $SqlServer = New-Object Microsoft.SqlServer.Management.Smo.Server
    $SqlServer.ConnectionContext.ConnectionString = $ConnectionString
    $SqlServer.Status
    
    • #99417

      Kamil
      Participant

      Good day.
      I was thinking more along the line of writing a certain string to the port. Then getting a certain response, which will indicate that there is a high probability that this port is listened to by MS SQL Server.
      The connection string in your example contains 55272, is it a port number?
      Also, since trusted_connection = true does it mean that the current domain user must have access rights to the sql server?

      Regards

You must be logged in to reply to this topic.