Focus on Microsoft Technologies - Tutorials, Articles, Code Samples.

Thursday, September 14, 2006

why System.InvalidCastException comes whild calling OdbcConnection.GetSchema

 A System.InvalidCastException exception may occur when you call the OdbcConnection.GetSchema method in the .NET Framework 2.0


The OdbcConnection.GetSchema method calls the SQLGetTypeInfo function in the ODBC API. The SQLGetTypeInfo function returns a result set that contains several columns. Some ODBC drivers may implement a column by using an incorrect SQL data type. For example, some ODBC drivers implement the following columns by using a signed value:
These columns should use the SQL_SMALLINT value instead. The SQL_SMALLINT value is an unsigned value. If one of these columns uses a signed value, a System.InvalidCastException exception occurs when Microsoft ADO.NET tries to cast the value to a System.Int32 value.

Post a Comment