Wednesday, March 28, 2012

killing sqlservr.exe from sqlclr code

I keep getting different answers from different people on regarding if you can or cannot kill the hosting sql server process with an unsafe assembly. Can you do this? If so could you please attach a sample demonstrating this?

Thanks,

Derek

Uhh, delicate question. Sure Microsoft did everything to prevent this. I know that in beta this was sort of unstable, but right now I have no clue how to do this.
If someone has an example to do this, this should be reported as a bug to Microsoft in order to prevent this. But I would assume that the CLR hosting process is quite stable right now.


HTH, Jens Suessmeyer.


http://www.sqlserver2005.de

|||There are many ways to kill sql server. If we allow PInvoke or unsafe code, then the possibilities are endless. There is no way to prevent a user from calling TerminateProcess with PInvoke. We are more concerned with safe assemblies not corrupting the sql server process then a user focused on terminating sql server.

You can always write an XP to do the same anyway for instance.|||could you please give me some quick code in C#/VB.Net that will kill the hosting process in that case?|||I am only concerned about this becaseu I am a lead author on a sqlclr book.|||

Is this simple enough?

public static void killsql()
{
System.Environment.Exit(-1);
}

Steven

No comments:

Post a Comment