SQL Server 2008: How crash-safe is a CLR Stored Procedure that loads unmanaged libraries

前端 未结 2 1293
萌比男神i
萌比男神i 2020-12-11 08:47

We\'ve got a regular (i.e. not extended) stored procedure in SQL Server 2000 that calls an external exe. That exe, in turn, loads a .dll that came from an S

2条回答
  •  温柔的废话
    2020-12-11 09:13

    Since this code was originally used with extended stored procedures, it sounds like it is unmanaged code. Bugs in unmanaged code can easily crash your process.

    CLR integration is much more robust than extended stored procedures, but the code still runs in-process, so errors can take down or corrupt SQL Server. (For comparison, in theory, a SAFE CLR routine won't be able to corrupt SQL Server although even it could cause problems that reduce your server's availability without totally taking down the SQL Server.)

    Basically, the only ways to not crash SQL Server in this scenario are:

    1. Avoid using the functionality that crashes.
    2. Fix the buggy code.
    3. Run the code in a separate process (launch an executable, call a Windows service, call a web service, etc.). You can write a managed .NET DLL to perform this interaction. Most likely, you will still need to load it UNSAFE, but--if it is written properly--in reality it can be quite safe.

提交回复
热议问题