I've found only a few other threads on this topic including: "xp_cmdshell causes "Failed to initialize the Common Language Runtime (CLR) v2.0.50727 with HRESULT 0x80131022" error"
Followed the rabbit hole there and other locations but nothing seems to help.
In general it is suggested that this error is only related to 32 bit SQL Server, but it is occurring for me on 64 bit 2008 R2 with service pack 2. (windows 7 pro, so .NET 2 is integrated). Also reported on older OS types and versions of SQL. Again, not matching my problem.
I've tried changing memory usages, with the -g flag, etc. memory pressure seems unlikely (8GB and sample database is tiny with a few thousand records)
Two odd things which could be red herrings (or the key to everything).
It seems to fail on new Dells laptops (such as latitude e6430) right out of the box (with just SQL 2008 R2 and my app loaded). If I reload Windows from scratch (i.e. don't use the Dell factory image), the problem seems to go away, although I've
only done this once. It seems to work find on other computers, at least the couple other models we've had to test with.
The other odd behavior is that the xp_cmdshell seems to fail only when it becomes nested more that a few levels deep in the stored procedure calls. App calls stored procedure 1, which calls 2, which calls 3 where the xp_cmdshell fails (a directory list). if I move the code into stored proc 2 instead, it appears to work. Although because of the difficulties involved I've not been able to move all the 3rd level xp_cmdshell calls up to prove it definitively.
Also looked at and verified xp proxy and run with administrator rights,etc.
So, where to go next? I'm not sure what information is even helpful in diagnosing this one.
Thanks,
Brandon
Version info:
Microsoft SQL Server 2008 R2 (SP2) - 10.50.4000.0 (X64) Jun 28 2012 08:36:30 Copyright (c) Microsoft Corporation Developer Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1)
Error info:
Failed to initialize the Common Language Runtime (CLR) v2.0.50727 with HRESULT 0x80131022. You may fix the problem and try again later.
Error: 6511, Severity: 16, State:20