SqlDbType enumeration error

  • Follow


Hi,

When the sub below here is called on my visual studio localhost, there is 
not a single problem.
When I run my website with this sub on my IIS server I get the following 
error which doesn't make sence at all:

The SqlDbType enumeration value, 31, is invalid.
Parameter name: SqlDbType 
Description: An unhandled exception occurred during the execution of the 
current web request. Please review the stack trace for more information about 
the error and where it originated in the code. 

Exception Details: System.ArgumentOutOfRangeException: The SqlDbType 
enumeration value, 31, is invalid.
Parameter name: SqlDbType


Here is my code:

Public Function setApproval(ByVal month As String, ByVal user As String) As 
Boolean
    Dim conn As New SqlClient.SqlConnection
    conn = ConnectToSQLdb()
    If conn Is Nothing Then
      Return False
      Exit Function
    End If
    Dim dMonth As Date = CDate("01 " + month)

    Dim sb As New StringBuilder
    sb.AppendLine("UPDATE " & SQLTable.TimeSheetData)
    sb.AppendLine("SET " & TimeS.Approved & " = 'True', " & 
TimeS.ApprovalDate & " = @approvalDate")
    sb.AppendLine("WHERE MONTH(" & TimeS.Datum & ")=@maand AND YEAR(" & 
TimeS.Datum & ")=@jaar AND " & TimeS.EmployeeNummer & "=@employeenr")
    myCMD = New SqlCommand(sb.ToString, conn)

    myCMD.Parameters.Add("@approvaldate", SqlDbType.Date).Value = Now
    myCMD.Parameters.Add("@maand", SqlDbType.Int).Value = dMonth.Month
    myCMD.Parameters.Add("@jaar", SqlDbType.Int).Value = dMonth.Year
    myCMD.Parameters.Add("@employeenr", SqlDbType.NVarChar, 15).Value = user

    Try
      myCMD.ExecuteNonQuery()
    Catch ex1 As Exception
      myError = "There was a problem with setting the approvedfield in the 
database!"
      conn.Close()
      Return False
    End Try
    conn.Close()
    Return True
  End Function

How can I solve this?
What is causing it?

rg,
Eric

1
Reply Utf 2/17/2010 4:19:02 PM

On 2010-02-17 17:19, Eric wrote:
> When the sub below here is called on my visual studio localhost, there is
> not a single problem.
> When I run my website with this sub on my IIS server I get the following
> error which doesn't make sence at all:
>
> The SqlDbType enumeration value, 31, is invalid.
> Parameter name: SqlDbType
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information about
> the error and where it originated in the code.
>
> Exception Details: System.ArgumentOutOfRangeException: The SqlDbType
> enumeration value, 31, is invalid.
> Parameter name: SqlDbType
>
>
<snip>
>      myCMD.Parameters.Add("@approvaldate", SqlDbType.Date).Value = Now

You're using the new Date type, which is only supported from SQL Server 2008 
and .NET 2.0 SP1 onwards. The server likely has the pre-SP1 .NET 2.0 
installed. You'll want to install .NET 3.5, which also updates the 2.0 CLR 
to SP2.

You might also have made a simple typo if you're *really* using a DATETIME 
field (which is supported in all versions of SQL Server).

-- 
J.
0
Reply Jeroen 2/17/2010 6:46:27 PM


1 Replies
1611 Views

(page loaded in 0.611 seconds)

6/17/2014 6:57:39 AM


Reply: