Solved

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

Posted on 2004-04-08
3
614 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 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

11 Experts available now in Live!

Get 1:1 Help Now