How to close a database connection in SQL Server?

In SQL Server, there are two ways to close a database connection.

  1. Take someone’s life
KILL { session_id | @spid }

session_id is the session ID of the connection to be closed, @spid is a variable that can be assigned the session ID of the connection to be closed. For example, to close the connection with session ID 50, you can use the following command:

KILL 50
  1. You can close the connection using SQL Server Management Studio (SSMS) graphical interface. Here is an example of closing a connection using SSMS.
  1. Open SSMS and connect to the SQL Server database.
  2. In the “File Explorer”, expand the “Connections” node to locate the connection that you want to close.
  3. Right-click on the link and choose the “Disconnect” option.
  4. Confirm the connection is closed.

No matter which method you use to close the connection, be careful to ensure that the correct connection is closed to avoid any negative impact on the system.

bannerAds