Part 2 ;-)The last part is the log procedure itself. And it is using the DMO connection and the user function so make sure LogConstructur is called before!LogActionCREATE PROCEDURE LogAction @iIDExportLog int, @sMessage varchar(500), @sLogCategory char(1), @sSource varchar(50), @errorcheck int=0 OUTPUT ASdeclare @LogObject intdeclare @oDatabase intdeclare @oQueryResults intdeclare @Length intdeclare @ErrorMsg varchar(255)declare @Source varchar(255)declare @Error intdeclare @CurrentDB varchar(255)declare @SQL varchar(8000)-- Get current objecttoken for log connectionselect @LogObject = dbo.MFF_GetLogObject()-- Set the database object to be the current database-- (We do this so we don't need to execute the SQL against the-- SQLServer object, which would require explicit DB prefixing)SELECT @CurrentDB = DB_NAME()SELECT @CurrentDB = 'Databases("' + RTRIM(@CurrentDB) + '")'EXEC @Error = sp_OAGetProperty @LogObject, @CurrentDB, @oDatabase OUTIF @Error <> 0 GOTO OA_Error -- Build the SQL string-- This is my version. Add your code. Change the insert or call-- another procedure. Do whatever you like but KEEP YOUR-- DATABASE CLEAN!SET @SQL = 'insert into LogDetail (IDExportLog, Message, LogCategory, Source, Zeit) values (' + cast(@iIDExportLog as varchar) + ', ''' + @sMessage + ''', ''' + @sLogCategory + ''', ''' + @sSource + ''', getdate())'-- Execute the SQL (this will NOT be rolled back)-- We could use ExecuteImmediate here, but it doesn't return a result-- and we found while debugging that you really NEED thatSET @Length = LEN(@SQL)SET @ErrorMsg = '' -- Must initialize the @ErrorMsg stringEXEC @Error = sp_OAMethod @oDatabase, 'ExecuteWithResultsAndMessages', @oQueryResults OUTPUT, @Length = @Length, @Command = @SQL , @Messages = @ErrorMsg OUTPUTIF @Error <> 0 GOTO OA_ErrorEXEC @Error = sp_OADestroy @oDatabaseEXEC @Error = sp_OADestroy @oQueryResultsreturnOA_Error: -- Get the error text EXEC sp_OAGetErrorInfo @LogObject, @Source OUT, @ErrorMsg OUT SELECT @ErrorMsg = CONVERT(CHAR(16), @Error) + ': ' + @ErrorMsg + ' (Source: ' + @Source + ')' select @errorcheck = 1 print @ErrorMsg returnGO
That´s it. Have fun!DanielEdited by - Daniel_Buchholz on 04/05/2002 02:42:22