Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
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 video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

808 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