Home All Groups Group Topic Archive Search About

date type conversion error ignored

Author
24 Jan 2006 4:15 PM
Richard Chandler
Win2003 Server sp1, SQLServer2000 sp4, .Net 1.1

The code below executes fine without throwing an exception.

Unfortunately, in my real problem the command executes a stored proc, which
completes happily despite this error. The error results in NULL values in
rows that overflow the data type and values for the ones that don't and no
way of knowing that the operation has partially failed apart from looking at
the table and spotting it.

I've got the problem with ODBC really, but I tried ADO.Net to find out if
it's been resolved by a newer technology ... and it hasn't.

Am I missing something here ?

(I used the SQLDataReader as I recall in ODBC you get the output from the
command as the last recordset or something like that).

<c#>
using System;

namespace type_error_in_sql
{
    class Class1
    {
        [STAThread]
        static void Main(string[] args)
        {
            try
            {
                System.Data.SqlClient.SqlConnection    lCnx    = new
System.Data.SqlClient.SqlConnection(
"server=localhost;database=master;integrated security=sspi;" ) ;
                lCnx.Open() ;

                System.Data.SqlClient.SqlCommand        lCmd    = lCnx.CreateCommand() ;
                lCmd.Connection    = lCnx ;
                lCmd.CommandText  = "select cast( 1234.1234 as decimal(3,3) )" ;
                lCmd.CommandType    = System.Data.CommandType.Text ;

                System.Data.SqlClient.SqlDataReader    lRdr    = lCmd.ExecuteReader() ;

                if ( lRdr.HasRows )
                {
                    int x = 0 ;
                }

                lCnx.Close() ;
            }
            catch( System.Data.SqlClient.SqlException se )
            {
                int x = 1 ;
            }
            catch( System.Exception e )
            {
                int x = 1 ;
            }
        }
    }
}
</c#>

Thanks,

Binary Bear

Author
24 Jan 2006 9:11 PM
Jesús López
It seems that both ANSI_WARNINGS and ARITHABORT are OFF:

http://msdn2.microsoft.com/en-us/library/ms189118.aspx

Regards:

Jesús López
VB MVP
Author
25 Jan 2006 10:21 AM
Richard Chandler
"Jesús López" wrote:
>
> It seems that both ANSI_WARNINGS and ARITHABORT are OFF:
>

Doh ! 8-)

Thanks Jesús.

AddThis Social Bookmark Button