I'm working on a Windows Forms application in VB, using Visual Studio 2010. The application has an option to open a form that contains a ReportViewerControl which displays an SSRS report housed on our MS SQL Server 2008 R2 server. When the form is displayed the report shows up as expected and can be closed without any errors that I can see.
However, I've noticed that the session ID assigned when that form is launched remains open well after the form has been closed. In fact, it stays open even after the application itself is shut down. It does eventually go away - about 10 minutes later, which is (I believe) the default timeout value for the ServerReport class.
For reference, I'm seeing the session id hanging out there when I run the following from SSMS:
SELECT session_id FROM sys.dm_exec_sessions WHERE login_name = 'MyLoginName';
I'd like to avoid shorting the timeout value, in the hopes of preventing timeout errors for the users. However, I'd also like to close that session safely when the form is closed, as the session is no longer needed and seems like a waste of resources to have it left open.
My question is, what is the best way to safely close the SQL session when the report form is closed?