Hi All,
We're using the 1.1. Framework against SQL Server 2000, and are having a
strange issue where we don't get errors back from the stored procedure, i.e.
the exception never gets thrown.
The scenario is this:
1.) Set up SqlConnection and SqlCommand
2.) Set SqlDataReader equal to the return value from
SqlCommand.Exec uteReader
3.) Check SqlDataReader.H asRows() to see if there is any data in the stream
If we do these things, but do not call SqlDataReader.R ead(), we never get
any exceptions from the stored procedure.
Our understanding was that you want to check SqlDataReader.H asRows() before
doing anything, in case there was no data returned.
This apparently does not work.
The mysterious part is why the exception does not fire on step #2
(SqlCommand.Exe cuteReader() ).
We use SqlDataReader objects to stream stored procedure results back when we
have a smallrowsets.
Normally, our code looks like so:
'...set up connection and command...
rdr = cmd.ExecuteRead er
While rdr.Read
'Process row...
Loop
'et cetera...
In this case, the exception fires normally.
However, one of our developers tried:
If rdr.HasRows Then
While rdr.Read
'Process row..
Loop
End If
This results in the total suppression of SQL Server errors that occurred in
the stored procedure.
Why does this occur?
Of what use is HasRows() if it doesn't throw the exceptions that are
apparently waiting in the SqlDataReader stream?
Are there any other "scenarios" we should be aware of which would suppress
the SQL Exceptions? This is scary.
Here is the necessary repro information:
/*SQL Server 2000*/
USE Northwind
GO
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id =
object_id(N'[dbo].[ADOTest]') and OBJECTPROPERTY( id, N'IsUserTable') = 1)
DROP TABLE [dbo].[ADOTest]
GO
IF EXISTS (SELECT * from dbo.sysobjects WHERE id =
object_id(N'[dbo].[selADOTest]') and OBJECTPROPERTY( id, N'IsProcedure') = 1)
DROP PROCEDURE [dbo].[selADOTest]
GO
CREATE TABLE
ADOTest
(
DateVal varchar(19) NOT NULL
)
GO
INSERT INTO ADOTest (DateVal) VALUES ('2005-02-2811:55.000')
GO
CREATE PROCEDURE dbo.selADOTest
AS
SET NOCOUNT ON
SELECT CONVERT(datetim e, DateVal) AS DateVal FROM ADOTest
GO
GRANT EXECUTE ON selADOTest TO public
GO
'VB.Net: (Paste code into the click event of a button on a Windows Form):
Dim conn As System.Data.Sql Client.SqlConne ction, cmd As
System.Data.Sql Client.SqlComma nd, rdr As System.Data.Sql Client.SqlDataR eader
Dim hasRows As Boolean
Try
conn = New
System.Data.Sql Client.SqlConne ction("SERVER=D EV;DATABASE=Nor thwind;Integrat ed
Security=SSPI;" )
conn.Open()
cmd = conn.CreateComm and
cmd.CommandType = CommandType.Sto redProcedure
cmd.CommandText = "dbo.selADOTest "
rdr = cmd.ExecuteRead er
If rdr.HasRows Then
While rdr.Read
Debug.WriteLine (rdr("DateVal") )
End While
End If
MsgBox("Success fully executed stored procedure.")
Catch sqlEx As System.Data.Sql Client.SqlExcep tion
MsgBox("SQLExce ption: " & sqlEx.Message)
Catch appEx As ApplicationExce ption
MsgBox("Applica tionException: " & appEx.Message)
Finally
If Not IsNothing(rdr) Then
rdr.Close()
rdr = Nothing
End If
If Not IsNothing(cmd) Then
cmd = Nothing
End If
If Not IsNothing(conn) Then
If conn.State = ConnectionState .Open Then
conn.Close()
End If
conn = Nothing
End If
End Try
'Try it with the "If rdr.HasRows() Then.." and also without.
'You'll see what I mean.
'The exception will not fire with the HasRows() check in place.
Thanks,
James Hokes 0 2505 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: jrefactors |
last post by:
I want to know the differences between SQL Server 2000 stored
procedures and oracle stored procedures? Do they have different
syntax? The concept should be the same that the stored procedures
execute in the database server with better performance?
Please advise good references for Oracle stored procedures also.
thanks!!
|
by: Rhino |
last post by:
I've spent the last couple of hours trying to figure out how to debug a Java
stored procedure and am just going in circles. The last straw came when I
got "Cannot open input stream for default" when I launched the IBM
Distributed Debugger via
D:\IBMDebug>idebug.exe -qdaemon -quiport=8000,8001
First, a bit of background.
I am running DB2...
|
by: Kent Lewandowski |
last post by:
hi all,
Recently I wrote some stored procedures using java jdbc code
(admittedly my first stab) and then tried to implement the same within
java packages (for code reuse). I encountered problems doing this.
I wanted to implemented a generic "Helper" class like this:
/**
* Helper
|
by: Rhino |
last post by:
I am trying to determine the behaviour of stored procedures in DB2 V8.2.x in
Windows/Unix/Linux and how I can control that behaviour. Some documentation
in the manuals is confusing the issue somewhat.
First, am I right in understanding that the normal behaviour of a stored
procedure, fenced or unfenced, is to only go into memory when it is...
|
by: James Hokes |
last post by:
Hi All,
We're using the 1.1. Framework against SQL Server 2000, and are having a
strange issue where we don't get errors back from the stored procedure, i.e.
the exception never gets thrown.
The scenario is this:
1.) Set up SqlConnection and SqlCommand
2.) Set SqlDataReader equal to the return value from
SqlCommand.ExecuteReader
| |
by: Maks Romih |
last post by:
I'm not experienced in db2, but I have to write some rather complex
processing with stored procedures for db2 on as400.
The database consists of some twenty tables and is prepared in advance
so it does not change, while I run my procedures. I call the
procedures over ODBC from a Microsoft Access and Microsoft Windows
client. The procedures...
|
by: phil |
last post by:
Hi,
With the code below, i get the error:
ExecuteReader: Connection property has not been initialized.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details:...
|
by: Givisiez |
last post by:
Hi
I'm programming a windows application. I store values on a SQL-
database.
Now I've a problem reading the values stored.
I want to read a whole column from a table. I tried my SQL Command in
the "Query" from the Microsoft Visual Studio. There I get exactly the
values, which I want.
When I use the same command with a ExecuteReader, the...
|
by: davek604 |
last post by:
Hello
The code below is part of a program which gets usernames from a MySQL database. If the username isn't in the database I want to call another form to add the user + some other details. The form only appears for half a second and disappears, but if I change it to Output.HasRows = True then the form opens no problem. Any help really...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| | |