views:

526

answers:

2

Hi,

I codded a CLR stored procedure (listed below) The line of code where the exception is thrown was added just for the purpose of having the exception logged in EventLog I deployed the assembly and created the stored proc in database However when I execute the stored procedure no entry is logged in Windows' EventLog

If the code where the EventLog is used in a separate Windows console application then the exception is logged

Any help would be appreciated

Thanks,

arunganu

.......
using System.Diagnostics;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
.......
[Microsoft.SqlServer.Server.SqlProcedure]
public static SqlInt32 Posting(SqlString tag)
{
  try
  {
      ...
       throw new ArgumentException("arg exc");
      ...
      return 0;    //  success
  }
  catch (Exception e)
  {
      try
      {
          EventLog PostingLog = new EventLog("Application");
          PostingLog.Source = "Posting";
          PostingLog.WriteEntry(e.Message, EventLogEntryType.Error);
          PostingLog.Close();
          return 1;   //  error
      }
      catch  // in case when another exception is raised from the try block above
      {
          return 1;   // error
      }
  }
}
+1  A: 

IIRC, you need to give the assembly unsafe permission.

leppie
A: 

Hi Leppie,

It worked ! Sorry for delay

Thanks,

arunganu