How to diagnose ArgumentOutOfRangeException on SqlDbType?

3.6k Views Asked by At

We have some customers using our .NET 2.0 thick-client app that experience strange, intermittent errors reading data from a SQL 2000 SP4 Server, where the actions succeeded just moments earlier. We have some customers using SQL 2000 (and many using 2005) where these errors do not occur.

One thing I notice is that the app in our testing environments references System.Data 2.0.50727.3053; whereas the app references 2.0.50727.1433 on the customer's systems. What is the difference between these two revisions and could it be related to the errors described below?

Here is an example of the error's stack trace where the enumeration value is 8, but I have plenty more instances where the "out of bounds" enumeration value is 4 or 14 with the same exact stack trace. Are the enumeration values findable sometimes but not at other times? What about when the same portion of the app runs without errors?

TYPE: System.ArgumentOutOfRangeException
MSG: The SqlDbType enumeration value, 8, is invalid.
Parameter name: SqlDbType
SOURCE: System.Data
SITE: GetSqlDataType

at System.Data.SqlClient.MetaType.GetSqlDataType(Int32 tdsType, UInt32 userType, Int32 length)
at System.Data.SqlClient.TdsParser.CommonProcessMetaData(TdsParserStateObject stateObj, _SqlMetaData col)
at System.Data.SqlClient.TdsParser.ProcessMetaData(Int32 cColumns, TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.NextResult()
at Ceoimage.Basecamp.Data.Document._GetDocumentModelWithCollections(IDataReader rdr)

Update: I just downloaded System.Data from one of the clients' workstations. They had two versions in the GAC, one in the GAC directory and one in the GAC_32 directory. In GAC, the version number is 1.14322.2365. In GAC_32, the version number is 2.0.50727.1433 as described above. In all three versions, however, the SqlDbType enumerable maps the same int values to the same types for those in the error messages:

DateTime = 4
Int = 8
UniqueIdentifier = 14

I am afraid the version might be a red herring: if the problem has to do with framework versions, shouldn't the problem happen 100% of the time rather than being transient?

3

There are 3 best solutions below

0
On

This ancient discussion tracks a similar error down to using a connection created on one thread to run a query within a different thread. SqlConnection "instance members are not guaranteed to be thread safe". If you application is multi-threaded, make sure connections are used properly.

The problem may also be something SQL-Server side that has been resolved in more recent versions.

I am answering here because I've encountered this error when using SqlCommand.Cancel with SQL 2005. (There are a handful of exceptions that occur in addition to 'Operation cancelled by user' depending on when the query is cancelled.) I see it as a 'unexpected response from the server' error... it's probably a good idea to clear the connection pool if it does happen.

How to cancel a long-running Database operation?

How to force a SqlConnection to physically close, while using connection pooling?

1
On

Your client is on .NET 2.0 without 3.5 installed. Your test servers are 3.5. The only things added to the enumeration in 3.5 are:

Structured
Date
Time
DateTime2
DateTimeOffset

This does not mean that there are not some underlying changes.

If possible, I would test the app under 2.0 without 3.5 installed and see what errors you are getting. That should give you a good place to start.

To figure out the point of error, I would have to iterate through the enumeration and see what order the items are in the enum. Reflector is a great tool for doing this, but you will have to do it on both a 2.0 system and a 3.5 system to see the changes.

0
On

this solution may solve your problem:

Is your local box using SQL server 2008 but the other box is 2005? The @RUNTIME parameter is type SqlDbType.Time. That type did not exist in SQL server 2005. Also SqlDbType.Time has a value of 32 as the exception says. You can't store just time values before sql server 2008. You have to store @RUNTIME as a SqlDbType.DateTime in 2005.

And if you use .NET Framework 2.0 use must Install .NET Framework 2.0 SP2 and sql2008 to solve this problem.