Wednesday 2 May 2018

Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.

I was working on a SSRS report in SQL Server 2008 R2, report had So Many Datasets. When I was running the report I was getting the message "Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached." I tried to run the individual dataset's script in SSMS, it was working fine. I googled and Increase the Pool Size and Timeout duration in DataSource Connection String. Default Pool Size value is 100.


Data Source=ServerName;Initial Catalog= DatabaseName; Max Pool Size=500; Connection Timeout=1000;

This worked for me. For other applications like Asp.Net and others can use the connection string like:


ConnectionString="Data Source=ServerName;Initial Catalog= DatabaseName;Persist Security Info=True;User ID=SA;Password=UserPassword;Pooling='True'; Max Pool Size=500; Connection Timeout=1000;"


Reference: Govind Badkur(http://sqlserver20.blogspot.com)

Friday 27 April 2018

Recover Unsaved SQL Query Scripts

If accidentally ssms is closed and you lost the script, or to retrieve previous 24 hours executed scripts, then below script will be helpful.

SELECT execquery.last_execution_time AS ExecutionDateTime, execsql.text AS QueryScript FROM sys.dm_exec_query_stats AS execquery
CROSS APPLY sys.dm_exec_sql_text(execquery.sql_handle) AS execsql
ORDER BY execquery.last_execution_time DESC

For the older scripts, you may get the recovery files from the below location :

C:\Documents and Settings\Username\My Documents\SQL Server Management Studio\Backup Files\


Reference: Govind Badkur(http://sqlserver20.blogspot.com)