Solved

Object Must Implement IConvertible.   ------ Error.

Posted on 2004-04-08
3
613 Views
Last Modified: 2008-03-06
I am constantly getting this error, how ever i implement or change my code.

the error is "Object must Implement IConvertible"

Dont know how to solve, it. I am getting this error at the last line. SqlCmd.ExecuteNonQuery();


Any Ideas.


Here is the Code, Cut and paste to VS.NET.            


                                  #region public static LogErrorToSqlServer
            static public void LogErrorToSQLServer(
                                          int errorCode,
                                          string errorSource,
                                          string errorCulture,
                                          string errorMessage)
            {
                  SqlConnection SqlConn = null;
                  SqlCommand SqlCmd = null;
                  
                  try
                  {
                        SqlConn = new SqlConnection(Common.DataBaseConnectionString);
                        SqlCmd = new SqlCommand("spInsertError",SqlConn);
                        SqlCmd.CommandType = CommandType.StoredProcedure;
                        
                        SqlParameter paramServer = new SqlParameter("@Server",SqlDbType.VarChar,8);
                        paramServer.Value = System.Web.HttpContext.Current.Server.MachineName;
                        paramServer.Direction = ParameterDirection.Input;
                        SqlCmd.Parameters.Add(paramServer);
                  
                        SqlParameter paramPageURL = new SqlParameter("@PageURL",SqlDbType.VarChar,127);
                        paramPageURL.Value = System.Web.HttpContext.Current.Request.Url;
                        paramPageURL.Direction = ParameterDirection.Input;
                        SqlCmd.Parameters.Add(paramPageURL);

                        SqlParameter paramQueryString = new SqlParameter("@QueryString",SqlDbType.VarChar,127);
                        paramQueryString.Value = System.Web.HttpContext.Current.Request.QueryString;
                        paramQueryString.Direction  = ParameterDirection.Input;
                        SqlCmd.Parameters.Add(paramQueryString);

                        SqlParameter paramSource = new SqlParameter("@ErrorSource",SqlDbType.VarChar,32);
                        paramSource.Value = errorSource;
                        paramSource.Direction  = ParameterDirection.Input;
                        SqlCmd.Parameters.Add(paramSource);

                        SqlParameter paramCode = new SqlParameter("@ErrorCode",SqlDbType.Int,4);
                        paramCode.Value = errorCode;
                        paramCode.Direction = ParameterDirection.Input;
                        SqlCmd.Parameters.Add(paramCode);

                        SqlParameter paramCulture = new SqlParameter("@ErrorCulture",SqlDbType.VarChar,8);
                        paramCulture.Value = errorCulture;
                        paramCulture.Direction = ParameterDirection.Input;
                        SqlCmd.Parameters.Add(paramCulture);

                        SqlParameter paramMessage = new  SqlParameter("@ErrorMessage",SqlDbType.VarChar,512);
                        paramMessage.Value = errorMessage;
                        paramMessage.Direction = ParameterDirection.Input;
                        SqlCmd.Parameters.Add(paramMessage);

                        SqlConn.Open();
                        SqlCmd.ExecuteNonQuery();
                  }
                  catch (Exception ex)
                  {
                        ex.ToString();
                  }
                  finally
                  {
                        
                        if (SqlCmd != null) SqlCmd.Dispose();
                        if (SqlConn != null) { if (SqlConn.State != System.Data.ConnectionState.Closed) SqlConn.Close(); SqlConn.Dispose(); }
                  }
            }
            #endregion
0
Comment
Question by:steve_mick972
  • 2
3 Comments
 
LVL 12

Assisted Solution

by:dfiala13
dfiala13 earned 100 total points
ID: 10789090
In this case one of your parameters is not the type you expect.  Double check the signature on your stored proc. Could also be some funky characters in your query string param.  Brute force case, strip down to one param and add them in until one breaks.
0
 
LVL 22

Accepted Solution

by:
_TAD_ earned 400 total points
ID: 10791240


it's also possible that you might be trying to send a C# null value to the stored procedure when the stored procedure might allow a DbNull which is different than a C# null.

But now that I've spit that out, I think it actually throws a different error than what you've provided.


follw dfiala's suggestion and if some reason that doesn't pan out, then look for a data error
0
 
LVL 22

Expert Comment

by:_TAD_
ID: 10791248


Also... if you post the header to the stored procedure someone here may be able to point out your error (if you can't find it).
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Programmatically signing Word macros 4 61
Definitions and default visual studio colors 5 58
Problem to error 4 47
Angular - break the dataset in chunks? 7 40
Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now