473,402 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Reading the custom error messages from SQL

I have a stored procedure in SQL Server 2000, and I want to read the error
messages from this stored procedure.
Please help me for this question:

This is the stored procedure. Please supose than Column2 has no 0 values:

CREATE PROCEDURE dbo.ErrorTest
AS
SELECT Column1 FROM Table WHERE Column2 = 0
IF (@@ROWCOUNT <= 0) GOTO RollB
RETURN 1

RollB:
RAISERROR('Error in the procedure...', 16, 1)
IF (@@TRANCOUNT > 0)
ROLLBACK TRANSACTION
RETURN 0
GO

This is the procedure in the client application:

SqlConnection MyConnection = new SqlConnection();
SqlCommand cmd = new SqlCommand("EXEC ErrorTest", MyConnection);
SqlDataReader dr = null;
try
{
MyConnection.Open();
cmd.Transaction =
cmd.Connection.BeginTransaction(IsolationLevel.Rea dCommitted);
dr = cmd.ExecuteReader();
if (dr.HasRows)
if (dr.read())
MyValue = dr["Camp1"];
dr.Close();
cmd.Transaction.Commit();
MyConnection.Close();
}
catch (Exception ex)
{
try
{
cmd.Transaction.Rollback();
}
catch
{
}
string errMessage = "";
for( Exception tempException = ex; tempException != null ; tempException
= tempException.InnerException )
errMessage += tempException.Message + Environment.NewLine +
Environment.NewLine;
MessageBox.Show(errMessage, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}

In this example the stored procedure returns the error message, but the
client applicatin isn't show it. The client applicatin showes an other error
message: The COMMIT TRANSACTION request has no corresponding BEGIN
TRANSACTION.
Please tell me:
1. How can I read in C# than the transaction was closed in the stored
procedure?
2. How can I show the error message from the stored procedure in the client
application?

Thank you!

Nov 17 '05 #1
1 2553
you should use transaction either in a stored procedure or in ADO. After
fixing this u should see that u receive error message

--

Thanks,
Yunus Emre ALPÖZEN
BSc, MCAD.NET

"Mihaly" <Mi****@discussions.microsoft.com> wrote in message
news:8F**********************************@microsof t.com...
I have a stored procedure in SQL Server 2000, and I want to read the error
messages from this stored procedure.
Please help me for this question:

This is the stored procedure. Please supose than Column2 has no 0 values:

CREATE PROCEDURE dbo.ErrorTest
AS
SELECT Column1 FROM Table WHERE Column2 = 0
IF (@@ROWCOUNT <= 0) GOTO RollB
RETURN 1

RollB:
RAISERROR('Error in the procedure...', 16, 1)
IF (@@TRANCOUNT > 0)
ROLLBACK TRANSACTION
RETURN 0
GO

This is the procedure in the client application:

SqlConnection MyConnection = new SqlConnection();
SqlCommand cmd = new SqlCommand("EXEC ErrorTest", MyConnection);
SqlDataReader dr = null;
try
{
MyConnection.Open();
cmd.Transaction =
cmd.Connection.BeginTransaction(IsolationLevel.Rea dCommitted);
dr = cmd.ExecuteReader();
if (dr.HasRows)
if (dr.read())
MyValue = dr["Camp1"];
dr.Close();
cmd.Transaction.Commit();
MyConnection.Close();
}
catch (Exception ex)
{
try
{
cmd.Transaction.Rollback();
}
catch
{
}
string errMessage = "";
for( Exception tempException = ex; tempException != null ; tempException
= tempException.InnerException )
errMessage += tempException.Message + Environment.NewLine +
Environment.NewLine;
MessageBox.Show(errMessage, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}

In this example the stored procedure returns the error message, but the
client applicatin isn't show it. The client applicatin showes an other
error
message: The COMMIT TRANSACTION request has no corresponding BEGIN
TRANSACTION.
Please tell me:
1. How can I read in C# than the transaction was closed in the stored
procedure?
2. How can I show the error message from the stored procedure in the
client
application?

Thank you!

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Lee | last post by:
I have created a custom log for my apps to write to. Writing to the log seems to be no problem, it's when I go to read it I get unexpected results. I have an application that reads the log and...
21
by: JoKur | last post by:
Hello, First let me tell you that I'm very new to C# and learning as I go. I'm trying to write a client application to communicate with a server (that I didn't write). Each message from the...
16
by: Bret Pehrson | last post by:
I've converted a non-trivial C++ library to managed, and get the following unhelpful linker error: Assignment.obj : error LNK2022: metadata operation failed (80131195) : Custom attributes are...
8
by: pmud | last post by:
Hi, I am using a compare validator in asp.net application(c# code). This Custom validator is used for comparing a value enterd by the user against the primary key in the SQL database. IF the...
3
by: Brad Wood | last post by:
If I add my own section to my Web.Config file of my (2.0) web service project (and refer to it by adding a "section" sub-element to a "configSections" element, I then get information messages...
1
by: CodeSeeker | last post by:
I have an application, which uses pop3 to read the messages from the mailbox, and it has been working fine for so many year. We recently have started changing this application to use java mail IMAP 4...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
1
by: asharda | last post by:
I have a custom property grid. I am using custom property grid as I do not want the error messages that the propertygrid shows when abphabets are entered in interger fields. The custom property...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
jinu1996
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...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.