Search code examples
sqlsql-serverbatch-filetelnetsql-server-agent

Is there a possibility to send a telnet command or start a bat file when I get a result in a SQL View?


I would like to send a Telnet command or start a *.bat file when I get a result in a SQL view. I am using SQL Express and so don't have the SQL Server Agent.

I am trying to launch a cue in a lighting software, 30 minutes before one of our shows starts. The software listens to Telnet commands or bat files.

Could anyone suggest a free software of a way to do this from within SQL Express Server thru SSMS?

Thanks in advance,


Solution

  • I think the best option you have is to use Windows Task Scheduler. Create a PowerShell script that selects the records from your View and if the count is greater than 0 launch the .bat file .

    Example :

    $query = "SELECT * FROM MY_VIEW"
    $results = Invoke-Sqlcmd -ServerInstance "yourserver\instance" -Database "yourdatabase" -Username "username" -Password "password" -Query $query
    if ($results.Count() -gt 0){
        C:/path_to_bat_file.bat
    }
    

    Links :

    https://learn.microsoft.com/en-us/powershell/module/sqlserver/invoke-sqlcmd?view=sqlserver-ps

    https://learn.microsoft.com/en-us/powershell/module/nettcpip/test-netconnection?view=win10-ps