27

For troubleshooting purposes, I would like to be able to check if a client can connect to a SQL Server instance, independent of the application that possibly can't connect to the SQL Server.

Is there an easy way (that means, not having to install 3rd party software) to do this using the default Windows system tools? Perhaps using scripts or network applications?

1
  • on my notebook i can create a sqlserver odbc connection and test access to the sqlserver. But I don't no if the sqlserver odc driver can be found on all clients that are configured to access sqlserver. but if it could be found this would be the next test after checking the reachiility of the server's sqlserver prot with telnet.
    – miracle173
    Commented Sep 6, 2012 at 14:21

4 Answers 4

20

If the server is using TCP/IP, then the simple way is to just telnet to the SQL Server port and see if it connects. By default, that's port 1433, so this should work:

telnet servername 1433

That will probably be appropriate in most cases.

If it's using a different port, or dynamic ports (common with a named instance), then you'll need to determine which port it's currently listening on. Check SQL Server configuration manager to see if it's a specific port, or dynamic ports. If it's using dynamic ports, then as long as you don't have multiple instances on the server, netstat -abn is probably the simplest way to find what it's using. Otherwise, dig through the Windows event log or the SQL Server error log for a message indicating which port is in use by the instance.

If SQL Server is using Named Pipes, then I believe if you're able to access shares on the machine, you have adequate network connectivity. This article says you can go further and try connecting to the IPC$ share:

http://msdn.microsoft.com/en-us/library/aa275787%28v=sql.80%29.aspx

net use \\servername\IPC$

That's written for SQL Server 2000, but I don't imagine this aspect has changed much, if at all.

3
  • 2
    That's not seeing if a client can "connect to a SQL Server instance". That's just testing to see if a port is listening. Commented Sep 5, 2012 at 12:40
  • 4
    ...which is seeing if a client system "can connect to a SQL Server instance, independent of the application that possibly can't connect to the SQL Server." Anything beyond the network connectivity is dealing with application issues.
    – db2
    Commented Sep 5, 2012 at 12:54
  • 1
    telnet client is not installed on every client
    – PollusB
    Commented Feb 18, 2021 at 19:51
37

A simple test method for SQL connectivity is to create an empty text file, with a file extension of "UDL". You can create it in Notepad. And it can have any name. I use "TestSQL.UDL"

Save it on the desktop of a windows PC and double click it.

A "Data Link Properties" dialog box will pop up where you can enter the IP address of the SQL server and also a SQL username and password.

Click the "Test Connection" button to see if you can connect.

enter image description here

5
  • Be sure to click the Provider tab and select the right OLE DB provider:"Microsoft OLE DB Provider for SQL Server"
    – DaveB
    Commented Apr 20, 2016 at 0:16
  • Dave, welcome, and good answer. You can edit your post (lower-left corner) to add this additional information. Then delete your comment. Commented Apr 20, 2016 at 0:58
  • 1
    This really is a great answer because it works on pretty much any server regardless of what or what isn't installed. All you need is Notepad. Thanks for this great answer, really helped me convince my client that SQL connectivity was working.
    – robnick
    Commented Oct 19, 2017 at 22:57
  • I agree with @robnick - this answer was so helpful in helping me fix an issue I was having. Thanks!
    – onekidney
    Commented Jan 6, 2020 at 20:30
  • In case double click doesn't work for you (for me, it was throwing error "File cannot be opened. Ensure it is a valid Data Link file"), right click and select "Properties".
    – ofri cofri
    Commented Aug 16 at 13:39
9

Provided you have the Microsoft.SqlServer.Smo assembly in your GAC on the local machine, this can be easily done with PowerShell:

[Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.Smo') | Out-Null

$server = New-Object Microsoft.SqlServer.Management.Smo.Server("YourSqlServerName")

# do a simple operation to see if you can get data
Try {
    $server.Version | Out-Null
    Write-Host "SQL Server connection successful!!!"
}
Catch [System.Exception] {
    Write-Host "Error connecting to SQL Server..."
}
0

There are so many ways to check connectivity - I got tired of googling every time I needed to check SQL connectivity from Windows, macOS, linux; to help with that, I created a docker image to test SQL connectivity. It's very (very) basic and I will probably improve this overtime, but hopefully it saves people time. Ok, so to test SQL connectivity simply run this command:

docker run -it ssaadi/test-sql-conn

It will ask you for host name, instance, port etc and then will try to connect and run select @@servername or display error if it fails.

The script is created in python and uses pymssql for sql connection -- the very very basic source code can be found here: https://github.com/sameersaadi/test-sql-conn

1
  • That doesn't seem to meet the criterion of "using the default Windows system tools".
    – mustaccio
    Commented Jan 12, 2022 at 23:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.