using System.Data.SqlClient; // Create a SqlCommand object SqlCommand cmd = new SqlCommand("SELECT * FROM Customers WHERE Country = 'USA'", connection); // Set the time-out value to 30 seconds cmd.CommandTimeout = 30; // Execute the command SqlDataReader reader = cmd.ExecuteReader(); // Check if the command is still running after 30 seconds if(!reader.IsClosed) { // If the command is still running, cancel it cmd.Cancel(); // Display an error message to the user Console.WriteLine("The query timed out and was cancelled."); }In this example, the SqlCommand object is executed with a time-out value of 30 seconds. If the command takes longer than 30 seconds to execute, the Cancel() method is called, and an error message is displayed to the user. The package library for the SqlCommand.Cancel() method is System.Data.SqlClient, which is included in the .NET framework.