首先程序的优化,不只是沿着一个点进行,往往都是程序配合服务器及数据服务器配置提升性能。
第一步:数据库链接优化
在数据库链接字符串中添加“Max Pool Size=32767;”,32767是数据库的最大链接数,也可以设置0个代表最大。
可以解决的错误:
1.超时时间已到。超时时间已到,但是尚未从池中获取连接。出现这种情况可能是因为所有池连接均在使用,并且达到了最大池大小。
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.
如何查询数据库用户的最大链接个数
A:查询所有用户的链接个数
select loginame,count(1) as Nums
from sys.sysprocesses
group by loginame
order by 2 desc
B:查询单个用户
--jxb数据库用户名
SP_WHO 'jxb'
--jxb数据库用户名
select spid,ecid,status,loginame,hostname,cmd,request_id
from sys.sysprocesses where loginame='jxb'
如果链接用户超出设置最大连接数,那么就会进入排序等待,设置“connect timeout