Re: ADO, SQLServer2000, stored procedure and errors
From: William \(Bill\) Vaughn (billvaRemoveThis_at_nwlink.com)
Date: 07/27/04
- Previous message: klaas: "simultaneous read/write ado"
- In reply to: Luigi: "ADO, SQLServer2000, stored procedure and errors"
- Messages sorted by: [ date ] [ thread ]
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
- Previous message: klaas: "simultaneous read/write ado"
- In reply to: Luigi: "ADO, SQLServer2000, stored procedure and errors"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|