Powershell would be my choice. But I'm curious what you mean by a specific ODBC connection as that is per process. So you wouldn't see it from another process unless you were doing this from a database server and querying the database itself. In that case it would depend upon your DB.
ODBC Connection

Paul
61
Reputation points
What is the best way to script to achieve the following on the client Windows 10 computer at a scheduled set time (Windows Task)...
To detect specific ODBC connection, if opens, close it.
batch file or console app?
You're not going to be able to solve it on the client side unless you own the code that is doing it. Connections are per process and your process cannot see another process'es connections. Even if it could it would have no way of knowing what is going on.
Traditionally I've seen this problem solved by writing a SQL script on the server that drops sessions that are inactive. This would be the workaround (as only it knows which connections there really are) until the problem code is fixed.
Yes, I am thinking to have a batch file or a console app that all SAS users to execute it at a set time which is scheduled daily in the Windows Task Scheduler on their Windows 10 workstation. By the way, all SAS users have the same naming on the SAS ODBC connection to the SQL server. Thanks.