Logging : Procedure or function has too many arguments specified.

Oct 14, 2010 at 9:28 PM

 When i configure Enterprise library 5.0 with logging, i am error like Procedure or function  has too many arguments specified. Even if i give 1 or many aruguments also i am getting the same exception. 

Please check my code and configuration and give some suggestion 

Exception

Exception Type: System.Data.SqlClient.SqlExceptionErrors: System.Data.SqlClient.SqlErrorCollectionClass: 16LineNumber: 0Number: 8144Procedure: WriteLogServer: Mysystem\SQLEXPRESSState: 2Source: .Net SqlClient Data ProviderErrorCode: -2146232060Message: Procedure or function WriteLog has too many arguments specified.Data: System.Collections.ListDictionaryInternalTargetSite: Void OnError(System.Data.SqlClient.SqlException, Boolean)HelpLink: NULL

 

C#

LogWriter defaultWriter = EnterpriseLibraryContainer.Current.GetInstance<LogWriter>();LogEntry entry = new LogEntry();entry.Categories.Add("DiskFiles");defaultWriter.Write(entry);

configuration 

<add name="Database Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"databaseInstanceName="TestDataBase" writeLogStoredProcName="WriteLog"addCategoryStoredProcName="AddCategory" formatter="Text Formatter"traceOutputOptions="None" filter="All" />

 

sp

PROCEDURE [dbo].[WriteLog]( @processId nvarchar(50), @LogId int OUTPUT)AS 
begin select 1 from dual; end

 

thanks in advance

Oct 15, 2010 at 12:37 AM

Did you create that WriteLog stored procedure or you modified the existing?  You should use the existing as it contains the parameters being supplied by the FormattedDatabase Trace Listener.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Oct 15, 2010 at 1:12 AM

Actually i modified the procedure to accept only i input parameter and one output parameter. If i remove all the arguments its throwing error like 'No argument in the SP'

 

PROCEDURE [dbo].[WriteLog]( @processId nvarchar(50), @LogId int OUTPUT)AS 
begin select 1 from dual; end

 

Above you can see the procedure... 

Oct 15, 2010 at 1:18 AM

You should not modify the stored procedure because the FormattedDatabaseTraceListener adds the parameters that is originally defined there.  If you modify it, you would have to create your custom database trace listener.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Oct 15, 2010 at 1:20 AM
Edited Oct 15, 2010 at 1:47 AM

So, it means, i want to use the stored procedure as it is..??... 

 

when i use, i am getting the below error:

 

Exception Information Details:======================================Exception Type: System.InvalidCastExceptionMessage: Object cannot be cast from DBNull to other types.Data: System.Collections.ListDictionaryInternalTargetSite: Int32 System.IConvertible.ToInt32(System.IFormatProvider)HelpLink: NULLSource: mscorlib

Oct 15, 2010 at 1:45 AM

Not exactly "as it is" because you can still modify the logic, probably add some sql statements inserting to other table or anything, but you cannot modify the parameters because their names are hardcoded in the source code.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Oct 15, 2010 at 1:53 AM

Yeah, now its calling the Procedure but i am getting error like below

Exception Information Details:======================================Exception Type: System.InvalidCastException

        Message: Object cannot be cast from DBNull to other types.Data: System.Collections.ListDictionaryInternalTargetSite: Int32 System.IConvertible.ToInt32(System.IFormatProvider)HelpLink: NULLSource: mscorlib

 

 

  Did i missed any thing in the code???

 

 // Create a Dictionary of extended properties                Dictionary<string, object> exProperties = new Dictionary<string, object>();                exProperties.Add("Extra Information", "Some Special Value");                // Create a LogEntry using the constructor parameters.                 defaultWriter.Write("Log entry with category, priority, event ID, severity, title, and extended properties.", "Database",                                                        5, 9008, TraceEventType.Warning, "Logging Block Examples", exProperties);                Console.WriteLine("Created a log entry with a category, priority, event ID, severity, title, and   extended properties.");                Console.WriteLine();                // Create a LogEntry using the constructor parameters.                 LogEntry entry = new LogEntry("LogEntry with category, priority, event ID, severity, title, and extended properties.", "Database",                                                8, 9009, TraceEventType.Error, "Logging Block Examples", exProperties);                defaultWriter.Write(entry);                Console.WriteLine("Created and written LogEntry with a category, priority, event ID, severity,     title, and extended properties.");                Console.WriteLine();                Console.WriteLine(@"Open the 'Logging.mdf' database in the Bin\Debug folder to see the results.");

Oct 15, 2010 at 2:06 AM

I don't see anything wrong with it.  I'll see if I can repro this.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Oct 15, 2010 at 2:11 AM

I struggle to find this for 2 weeks.. thanks for helping.. try to find the above error also....

Oct 15, 2010 at 2:12 AM

I was able to successfully log to the database.  Can you post your loggingConfiguration? 

In addition, did you modify any of the other related database objects?  Just to make sure, try deleting your Logging database and re-run the script. 

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Oct 15, 2010 at 2:25 AM

Thank you very much, its working fine now for me... Just i deleted and recreated the database connection again...

 

Thanks you once again. Can you tell me how to create my own TraceListener. So that i can call my own procedure..

Oct 15, 2010 at 2:30 AM

Creating a custom trace listener is included in the documentation.  I have a sample custom database trace listener.  Email me at entlib.support@avanade.com if you want a copy.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Oct 15, 2010 at 2:46 AM

Thanks in advance... I sent you mail.