Einzelnen Beitrag anzeigen

Elvis

Registriert seit: 25. Nov 2005
Ort: München
1.909 Beiträge
 
Delphi 2010 Professional
 
#2

Re: SQL MessageId aus einer SQLCLR Funktion

  Alt 16. Jan 2007, 09:38
Du kannst RaiseError als Command durch den Context abschicken. Du musst allerdings den Fehler, den RaiseError innerhalb der .Net Sproc auslöst abfangen und schlucken.
Dann könnte es funktionieren:
Code:
static void RaiseError(int messageId, int severity, int state)
{
  using (SqlCommand command = new SqlCommand("RaiseError(@messageId, @severity, @state)"))
  {
    command.Parameters.AddWithValue("messageId", messageId);
    command.Parameters.AddWithValue("severity", severity);
    command.Parameters.AddWithValue("state", state);
   
    try
    {
      SqlContext.Pipe.ExecuteAndSend(command);
    }
    catch {/*nüschts*/}
  }
}

static void RaiseError(string messageText, int severity, int state)
{
  using (SqlCommand command = new SqlCommand("RaiseError(@messageText, @severity, @state)"))
  {
    command.Parameters.AddWithValue("messageText", messageText);
    command.Parameters.AddWithValue("severity", severity);
    command.Parameters.AddWithValue("state", state);

    try
    {
      SqlContext.Pipe.ExecuteAndSend(command);
    }
    catch {/*nüschts*/}
  }
}
Keine Ahnung, ob das so stimmt. TSQL und das Fehlen von Exceptions darin sind so abartig...
Robert Giesecke
I’m a great believer in “Occam’s Razor,” the principle which says:
“If you say something complicated, I’ll slit your throat.”
  Mit Zitat antworten Zitat