Skip to main content

Troubleshooting SQL Connect

This guide covers three ways to test connectivity to a SQL Server database via PowerShell, a batch file, or a UDL file plus steps to check that the server itself is reachable and that the service is running.

Written by Sunil

Via PowerShell

  1. Prepare PowerShell for SQL Server

    • Run Install-Module -Name SqlServer to install the necessary module.

  2. Test the Connection

    Copy and paste the following script into a PowerShell window, replacing <DB>, <SQL_USER>, and <SQL_PASS> with your actual database name, SQL username, and password:

  3. Execute the Script

    • After updating the script with the correct values, run it to test the connection

Via Batch Files

  1. Install SQLCMD

    Download and install SQLCMD from the Microsoft Documentation if it isn't already installed

  2. Create and Configure a Batch File

    Right-click on the desktop, select New > Text Document, and enter the following script, replacing <DB>, <SQL_USER>, and <SQL_PASS> with your details:

  3. Rename and Run the Batch File

    • Change the file extension to .bat (e.g., TestConnection.bat) and execute it as an administrator.

Via UDL Files

  1. Create a UDL File. Right-click on the desktop, select New > Text Document, reveal file extensions, and rename the file to TestConnection.udl.

  2. Configure the UDL File. Right-click TestConnection.udl, choose Properties, and set up your SQL connection in the Data Link Properties dialog.

Check Server Communication

Open PowerShell as Administrator and run the following command, replacing mydesksqlconnect.accesshosting.co.uk with your server address and <Allocated SQL Connect Port> with your specific port:

📌Note: If there's no response, there might be an issue reaching the server from your machine.

Verify Service Status

Open CMD as Administrator and execute:

Ensure the path exists, then check netstat.txt for service status.

Did this answer your question?