I am getting the below error when executing my application on a Windows XP machine with .NET 2.0 installed. On my computer Windows 7 .NET 2.0 - 3.5 I am not having any issues. The target SQL server version is 2005. This error started occurring when I added the datetime to the stored procedure. I have been reading alot about using .NET datetime with SQL datetime and I still have not figured this out. If someone can point me in the right direction I would appreciate it.
Here is the where I believe the error is coming from.
private static void InsertRecon(string computerName, int EncryptState, TimeSpan FindTime, Int64 EncryptSize, DateTime timeWritten)
{
SqlConnection DBC = new SqlConnection("server=server;UID=InventoryServer;Password=pass;database=Inventory;connection timeout=30");
SqlCommand CMD = new SqlCommand();
try
{
CMD.Connection = DBC;
CMD.CommandType = CommandType.StoredProcedure;
CMD.CommandText = "InsertReconData";
CMD.Parameters.Add("@CNAME", SqlDbType.NVarChar);
CMD.Parameters.Add("@ENCRYPTEXIST", SqlDbType.Int);
CMD.Parameters.Add("@RUNTIME", SqlDbType.Time);
CMD.Parameters.Add("@ENCRYPTSIZE", SqlDbType.BigInt);
CMD.Parameters.Add("@TIMEWRITTEN", SqlDbType.DateTime);
CMD.Parameters["@CNAME"].Value = computerName;
CMD.Parameters["@ENCRYPTEXIST"].Value = EncryptState;
CMD.Parameters["@RUNTIME"].Value = FindTime;
CMD.Parameters["@ENCRYPTSIZE"].Value = EncryptSize;
CMD.Parameters["@TIMEWRITTEN"].Value = timeWritten;
DBC.Open();
CMD.ExecuteNonQuery();
}
catch (System.Data.SqlClient.SqlException e)
{
PostMessage(e.Message);
}
finally
{
DBC.Close();
CMD.Dispose();
DBC.Dispose();
}
}
Unhandled Exception: System.ArgumentOutOfRangeException: The SqlDbType enumeration value, 32, is invalid.
Parameter name: SqlDbType
at System.Data.SqlClient.MetaType.GetMetaTypeFromSqlDbType(SqlDbType target)
at System.Data.SqlClient.SqlParameter.set_SqlDbType(SqlDbType value)
at System.Data.SqlClient.SqlParameter..ctor(String parameterName, SqlDbType dbType)
at System.Data.SqlClient.SqlParameterCollection.Add(String parameterName, SqlDbType sqlDbType)
at ReconHelper.getFilesInfo.InsertRecon(String computerName, Int32 EncryptState, TimeSpan FindTime, Int64 EncryptSize, DateTime timeWritten)
at ReconHelper.getFilesInfo.Main(String[] args)