AppDomain is marked for unload due to memory pressure.

32-bit or 64-bit?  Have you tried tweaking the -g startup option for
sqlservr.exe?  That option configures the mem-to-leave area, which is where
SQLCLR pulls its memory from... It defaults to 256 MB on 32-bit systems, so
it might need a tweak.  Also, how are you doing the string concatenation in
your function?  Are you using StringBuilder, or the concatenation operator
(+)?  The latter could be causing part of your problem if it's what you're
using, as a lot more objects have to be allocated and deallocated than with
StringBuilder...

With regard to perf counters, the .NET counters are the most useful; there
are also a handful of DMVs you can use.  Check out Kimberly Tripp's white
paper, which talks about some of this towards the end:

http://www.sqlskills.com/resources/Whitepapers/SQL%20Server%20DBA%20Guide%20to%2
0SQLCLR.htm

 

 

-------------------------------

The amount of memory on the SQL Server would be my first concern.  1GB of RAM just isn't very much.  The OS alone can consume that relatively quickly, especially with IIS running the server as well.  Hyperthreading isn't generally recommended with SQL Server however, it has nothing to do with your problem currently, which is all memory based.  If anything having a true second core may make the Memory bottleneck that much more visible, as the processors may process faster than the memory can keep up and paging to disk begins to occur.

 

 

-------------------------------

 

You have to have significant memory issues to have both of these events happen together.  The proc cache is Bpool, and the CLR is MTL/VAS.  If you are on 32 bit SQL, then you need to set the -gparameter with 512 and it should resolve the issue with the app domain unload.  What else is running on the SQL Server?  Full Text Indexing/Integration Services/Reporting Services/IIS?  External Memory Pressure can easily trigger internal memory pressure in SQL.  If you have things other than just the SQL Database Engine running, then you may need to scale back your max server memory setting to 6GB or less, and you might consider removing the /3GB to give the 2GB  of VAS to the kernel mode since your bpool is being allocated in AWE.

 

Xprocs, Large Query Plans, connetions with a network packet size > 8060 bytes, SQLCLR, OLE Automation calls, all run in the MTL/VAS allocation taken by SQL Server.  What does your CLR Assembly do?  That is one question I have yet to see posed on this post?  Have you considered that you might have placed your CLR in the wrong place putting it in SQL Server?  What is the PermissionSet for the Assembly?  If it is UNSAFE then I would definately begin to consider that it might be doing the wrong thing inside of SQL Server.  Also check if you use XML documents in SQL that you are destroying the handles on them as this can leak memory, and if you are using OLE Automation calls that you destroy those objects properly as well.

AppDomain.CurrentDomain.AssemblyResolve 是.NET Framework提供的一个事件处理器,它允许开发者自定义应用程序域(Application Domain)在找不到引用的程序集时的行为。这个事件会在尝试加载某个程序集时引发,如果系统无法找到该程序集的完整版本,这时事件处理器可以提供替代的程序集版本或者是从其他源获取。 当你需要动态加载未知的或第三方库,或者处理缺失依赖的情况时,这个属性就非常有用。下面是一个简单的示例: ```csharp using System; using System.Reflection; public class CustomAssemblyResolver : MarshalByRefObject, AppDomainUnloadedEventHandler, IAssemblyResolve { // 实现 IAssemblyResolve 接口的成员 public Assembly Resolve(AssemblyName assemblyName) { if (assemblyName.Name == "MyCustomAssembly") // 假设我们正在寻找名为 "MyCustomAssembly" 的库 { try { return Assembly.LoadFrom("path_to_your_custom_library.dll"); // 替换为实际文件路径 } catch (Exception ex) { Console.WriteLine($"Failed to resolve assembly: {ex.Message}"); return null; // 返回 null 表示未找到或处理失败 } } else { // 如果不是你需要解决的,直接返回 null 或者抛出异常 return null; } } // AppDomainUnloadedEventHandler 处理域卸载事件 public void OnApplicationDomainUnloaded(AppDomain domain) { // 清理资源... } } // 注册自定义解决方案器 AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CustomAssemblyResolver.Instance.Resolve); // 主应用部分 try { // 尝试使用未知程序集 dynamic obj = Activator.CreateInstance(typeof(MyClassInCustomAssembly)); } catch (ReflectionTypeLoadException ex) { foreach (Exception e in ex.LoaderExceptions) { Console.WriteLine(e.Message); } } ``` 在这个例子中,当试图创建 `MyClassInCustomAssembly` 类时,如果没有找到 `MyCustomAssembly`,`CustomAssemblyResolver` 中的 `Resolve` 方法会被调用,尝试加载预定义的替换库或给出错误提示。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值