[dba-SQLServer] The command object exception

jwcolby jwcolby at colbyconsulting.com
Tue Jul 24 12:35:56 CDT 2007


I am trying to execute queries that build databases, build tables etc.  When
I executed the ExecuteNonQuery method with a query that built a database and
the database already exists, I got an error returned of -2147217900.  When I
tried to execute a sql statement with a general error I got the same error
returned.  How do I get meaningful error codes back from ExecuteNonQuery?

        Try
            mobjCmd.ExecuteNonQuery()
        Catch ex As OleDbException
            Select Case ex.ErrorCode
                Case -2147217900    'database already exists so ignore the
error
                Case Else
                    MessageBox.Show(ex.Message)
                    Return -3
            End Select
        End Try

John W. Colby
Colby Consulting
www.ColbyConsulting.com 




More information about the dba-SQLServer mailing list