Re: ADO, SQLServer2000, stored procedure and errors

From: William \(Bill\) Vaughn (billvaRemoveThis_at_nwlink.com)
Date: 07/27/04

  • Next message: Victor Koch: "Re: SQL SERVER 2000 Errors vi ADO OLDB"
    Date: Tue, 27 Jul 2004 10:44:26 -0700
    
    

    I setup a test to see how this behaves on my system (similar to yours) and
    the code threw an SQLException (as expected) and due to the severity, it
    abandoned the SP.

    As a design point, if you have a column that needs to be either a number or
    string, I suggest using the sqlvariant datatype.

    hth

    ________________________________

     Dim WithEvents cn As SqlConnection
        Dim cmd As SqlCommand
        Dim da As SqlDataAdapter
        Dim ds As New DataSet
        Dim dr As SqlDataReader

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
            Try
                cn = New SqlConnection("Data Source=betav7;integrated
    security=sspi;initial catalog=biblio")
                cn.Open()
                cmd = New SqlCommand("TestError", cn)
                cmd.CommandType = CommandType.StoredProcedure
                dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
                Do ' Process each resultset
                    ListBox1.Items.Add("Resultset")
                    Do While dr.Read
                        ListBox1.Items.Add("Data:" & dr.GetValue(0).ToString)
                    Loop
                    dr.Close()
                Loop While dr.NextResult
            Catch exS As SqlException
                MsgBox("SQLException:" & exS.Message & " Severity:" & exS.Class)
            Catch ex As Exception
                MsgBox("Infomessage:" & ex.ToString)
            End Try

        End Sub

        Private Sub cn_InfoMessage(ByVal sender As Object, ByVal e As
    System.Data.SqlClient.SqlInfoMessageEventArgs) Handles cn.InfoMessage
            MsgBox(e.Message)
        End Sub

    -- 
    ____________________________________
    William (Bill) Vaughn
    Author, Mentor, Consultant
    Microsoft MVP
    www.betav.com
    Please reply only to the newsgroup so that others can benefit.
    This posting is provided "AS IS" with no warranties, and confers no rights.
    __________________________________
    "Luigi" <Luigi@discussions.microsoft.com> wrote in message
    news:A2EDD568-57CF-4F1C-8765-FD053E5C9B3A@microsoft.com...
    > I have a stored procedure in a SQL Server 2000 database that contains the
    following code lines (@c is a varchar variable)
    >
    > 1 set @c = 'text data'
    > 2 if (CAST(@c as int) = -1)
    > 3 select '@c is -2'
    > 4
    > 5 select 'gone on after the error'
    >
    > If I execute the stored procedure in Query Analyzer what happens, as I
    expected, is that an error is raised (with an error level of 16) and lines 3
    and 5 are not executed (I can't see the result of select statements in the
    results pane of Query Analyzer).
    >
    > If I execute the stored procedure with and ADO.Command object, what
    happens is that Command.Execute is executed without any error. I can't see
    any entry in the Connection.Errors collection too.
    >
    > Is it correct ? I excpected an error reported also at client side by ADO.
    > I'm using ADO 2.6 SP2 and SQL Server 2000 SP3a.
    >
    > Thank you very much for any help.
    >
    > Luigi
    

  • Next message: Victor Koch: "Re: SQL SERVER 2000 Errors vi ADO OLDB"

    Relevant Pages

    • RE: How Do I Extract Data from my Form to load new table records?
      ... Steve: I have adapted your code as follows, but am ... Dim strSQL As String ... Open a "template table with a number of predefined "standard" rows ... file has 10 records in it, then every time I execute this, I would be adding ...
      (microsoft.public.access.formscoding)
    • Running Stored Procedure in a Loop
      ... I'm trying to execute a stored procedure in a loop while paging through ... Dim connString As String ...
      (microsoft.public.dotnet.framework.aspnet)
    • Re: Execute Method for Find Object
      ... During each iteration of the While loop, if .Execute returns ... Dim strSearch As String, strTerm As String ... Dim intIndex As Integer, intCounter As Integer, intLast As Integer ...
      (microsoft.public.word.vba.beginners)
    • Re: Database Extract Automation
      ... > database to execute JET SQL statements to move the data across. ... > Dim dbWSec 'As DAO.Workspace ... > 'Add code here to make sure UnsecuredDB doesn't ...
      (microsoft.public.access.externaldata)
    • Re: Looping!
      ... Well, McKirahan, this too takes about 30-35 seconds to execute! ... Now for the drop-downs - the no. ... the strSQL2 queries to populate the drop-downs. ... Dim strSQL1,strSQL2 ...
      (microsoft.public.inetserver.asp.db)