1.为了防止服务器因为sqlserver内存溢出造成卡顿或死机的情况,需设置数据库的内存限制大小,20G
2.程序找导出数据流的时候报错,这个时候就要对sqlserver做对应的处理了:
c#:System.OutOfMemoryException: 内存不足。
3.对sqlserver的内存资源进行释放
--use master --go --强制释放内存 alter procedure [dbo].ClearMemory as begin --清除所有缓存 DBCC DROPCLEANBUFFERS --打开高级配置 exec sp_configure 'show advanced options', 1 --设置最大内存值,清除现有缓存空间 ,10Gb exec sp_configure 'max server memory', 10000 EXEC ('RECONFIGURE') --设置等待时间 WAITFOR DELAY '00:00:05' --重新设置最大内存值 ,20Gb EXEC sp_configure 'max server memory', 20000 EXEC ('RECONFIGURE') --关闭高级配置 exec sp_configure 'show advanced options',0 END --执行存储过程 EXEC ClearMemory --其他参数参考 --清除存储过程缓存 DBCC FREEPROCCACHE --清除会话缓存 DBCC FREESESSIONCACHE --清除系统缓存 DBCC FREESYSTEMCACHE('All') --清除所有缓存 DBCC DROPCLEANBUFFERS -- 查看最小最大内存 select configuration_id,name 名称,minimum 配置最小值,maximum 配置最大值, is_dynamic 是否动态值,is_advanced 是否优先权,value_in_use 运行值, description 描述 from sys.configurations --查询内存使用情况,1000000kb=1Gb select * from sys.dm_os_performance_counters where counter_name IN('Target Server Memory (KB)','Total Server Memory (KB)') -- 内存状态 DBCC MemoryStatus