473,394 Members | 1,739 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,394 software developers and data experts.

Sql Exception in .net

I read
"Error Handling in SQL Server - a Background",
http://www.algonet.se/~sommar/error-handling-I.html and
"Implementing Error Handling with Stored Procedures",
http://www.algonet.se/~sommar/error-handling-II.html

and made the following changes:

if I take out the try I still get the error and I know
how to find whats wrong.

Please hekp??
Stan
-----------------------------------------------------------
Public Function CSVUpdate(ByVal Name As String, _
ByVal code As String, _
ByVal Caption As String, _
ByVal Price As Integer, _
ByVal SalePrice As Integer, _
ByVal id As String, _
ByVal path As String)

' Create Instance of Connection and Command
Object
Dim myConnection As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings
("ConnectionString"))
Dim myCommand As SqlCommand = New SqlCommand
("Update_CSV", myConnection)

' Mark the Command as a SPROC
myCommand.CommandType =
CommandType.StoredProcedure
' Add Parameters to SPROC
Dim parameterName As SqlParameter = New
SqlParameter("@Name", SqlDbType.NVarChar, 255)
parameterName.Value = Name
myCommand.Parameters.Add(parameterName)

Dim parametercode As SqlParameter = New
SqlParameter("@code", SqlDbType.NVarChar, 255)
parametercode.Value = code
myCommand.Parameters.Add(parametercode)

Dim parameterCaption As SqlParameter = New
SqlParameter("@Caption", SqlDbType.NVarChar, 4000)
parameterCaption.Value = Caption
myCommand.Parameters.Add(parameterCaption)
Dim parameterPrice As SqlParameter = New
SqlParameter("@Price", SqlDbType.Int, 4)
parameterPrice.Value = Price
myCommand.Parameters.Add(parameterPrice)

Dim parameterSalePrice As SqlParameter = New
SqlParameter("@SalePrice", SqlDbType.Int, 4)
parameterSalePrice.Value = SalePrice
myCommand.Parameters.Add(parameterSalePrice)

Dim parameterid As SqlParameter = New
SqlParameter("@Id", SqlDbType.NVarChar, 255)
parameterid.Value = id
myCommand.Parameters.Add(parameterid)

Dim parameterpath As SqlParameter = New
SqlParameter("@path", SqlDbType.NVarChar, 255)
parameterpath.Value = path
myCommand.Parameters.Add(parameterpath)

Dim parametererr As SqlParameter = New
SqlParameter("@err", SqlDbType.Int, 4)
parametererr.Direction =
ParameterDirection.Output
myCommand.Parameters.Add(parametererr)

Try
' Open the connection and execute the
Command
myConnection.Open()
myCommand.ExecuteNonQuery()
Catch myException As SqlException
Dim errornumber As Integer = CInt
(parametererr.Value)
End Try
myConnection.Close()

-----------------------------------------------------------
-----------------
CREATE PROCEDURE Update_CSV

@Name nvarchar(255),
@code nvarchar(255),
@Caption nvarchar(4000),
@Price int,
@SalePrice int,
@id nvarchar(255),
@path nvarchar(255),
@err int output
as
SET NOCOUNT ON

DECLARE @CountItems int

SELECT
@CountItems = Count(*)
FROM CSV

WHERE code = @code
IF @CountItems > 0 /* There are items - update the
current quantity */

UPDATE CSV
SET Name = @Name, code = @code,Id = @id,
Caption = @Caption, Price = @Price, [Sale-Price] =
@SalePrice,
path = @path
WHERE code = @code

ELSE /* New entry for this Cart. Add a new record */

INSERT INTO CSV
(Name, code, Caption, Price, [Sale-
Price], path,id)
VALUES (@Name, @code, @Caption, @Price, @SalePrice,
@path,@id)

SELECT @err = @@error if @err <> 0 return @err
GO
---------------------------

Jul 19 '05 #1
2 4356
What is the error, which line causes it?
What happens if you run the sproc in query analyzer?
"stanley j mroczek" <sm******@si.rr.com> wrote in message
news:08****************************@phx.gbl...
I read
"Error Handling in SQL Server - a Background",
http://www.algonet.se/~sommar/error-handling-I.html and
"Implementing Error Handling with Stored Procedures",
http://www.algonet.se/~sommar/error-handling-II.html

and made the following changes:

if I take out the try I still get the error and I know
how to find whats wrong.

Please hekp??
Stan
-----------------------------------------------------------
Public Function CSVUpdate(ByVal Name As String, _
ByVal code As String, _
ByVal Caption As String, _
ByVal Price As Integer, _
ByVal SalePrice As Integer, _
ByVal id As String, _
ByVal path As String)

' Create Instance of Connection and Command
Object
Dim myConnection As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings
("ConnectionString"))
Dim myCommand As SqlCommand = New SqlCommand
("Update_CSV", myConnection)

' Mark the Command as a SPROC
myCommand.CommandType =
CommandType.StoredProcedure
' Add Parameters to SPROC
Dim parameterName As SqlParameter = New
SqlParameter("@Name", SqlDbType.NVarChar, 255)
parameterName.Value = Name
myCommand.Parameters.Add(parameterName)

Dim parametercode As SqlParameter = New
SqlParameter("@code", SqlDbType.NVarChar, 255)
parametercode.Value = code
myCommand.Parameters.Add(parametercode)

Dim parameterCaption As SqlParameter = New
SqlParameter("@Caption", SqlDbType.NVarChar, 4000)
parameterCaption.Value = Caption
myCommand.Parameters.Add(parameterCaption)
Dim parameterPrice As SqlParameter = New
SqlParameter("@Price", SqlDbType.Int, 4)
parameterPrice.Value = Price
myCommand.Parameters.Add(parameterPrice)

Dim parameterSalePrice As SqlParameter = New
SqlParameter("@SalePrice", SqlDbType.Int, 4)
parameterSalePrice.Value = SalePrice
myCommand.Parameters.Add(parameterSalePrice)

Dim parameterid As SqlParameter = New
SqlParameter("@Id", SqlDbType.NVarChar, 255)
parameterid.Value = id
myCommand.Parameters.Add(parameterid)

Dim parameterpath As SqlParameter = New
SqlParameter("@path", SqlDbType.NVarChar, 255)
parameterpath.Value = path
myCommand.Parameters.Add(parameterpath)

Dim parametererr As SqlParameter = New
SqlParameter("@err", SqlDbType.Int, 4)
parametererr.Direction =
ParameterDirection.Output
myCommand.Parameters.Add(parametererr)

Try
' Open the connection and execute the
Command
myConnection.Open()
myCommand.ExecuteNonQuery()
Catch myException As SqlException
Dim errornumber As Integer = CInt
(parametererr.Value)
End Try
myConnection.Close()

-----------------------------------------------------------
-----------------
CREATE PROCEDURE Update_CSV

@Name nvarchar(255),
@code nvarchar(255),
@Caption nvarchar(4000),
@Price int,
@SalePrice int,
@id nvarchar(255),
@path nvarchar(255),
@err int output
as
SET NOCOUNT ON

DECLARE @CountItems int

SELECT
@CountItems = Count(*)
FROM CSV

WHERE code = @code
IF @CountItems > 0 /* There are items - update the
current quantity */

UPDATE CSV
SET Name = @Name, code = @code,Id = @id,
Caption = @Caption, Price = @Price, [Sale-Price] =
@SalePrice,
path = @path
WHERE code = @code

ELSE /* New entry for this Cart. Add a new record */

INSERT INTO CSV
(Name, code, Caption, Price, [Sale-
Price], path,id)
VALUES (@Name, @code, @Caption, @Price, @SalePrice,
@path,@id)

SELECT @err = @@error if @err <> 0 return @err
GO
---------------------------

Jul 19 '05 #2
i run the program and 188 records are processed before i get this error.

Server Error in '/' Application.
------------------------------------------------------------------------
--------

General network error. Check your network documentation.
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: System.Data.SqlClient.SqlException: General network
error. Check your network documentation.

Source Error:
Line 1865: ' Open the connection and execute the Command
Line 1866: myConnection.Open()
Line 1867: myCommand.ExecuteNonQuery()
Line 1868: myConnection.Close()
Line 1869:
Source File: C:\Market\Components\MaintenanceDB.vb Line: 1867

Stack Trace:
[SqlException: General network error. Check your network
documentation.]
System.Data.SqlClient.SqlCommand.ExecuteReader(Com mandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream) +723
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +194
Market.MK.MaintenanceDB.ProductUpdate(Int32 ProdIDkey, Int32
WholesalerId, String prodID, String prodName, String AuctionTitle,
String prodDescription, String prodImageSmallPath, String
prodImageLargePath, String RetailPrice, String CostPrice, String
SalePrice, String revPrice, String IdMetal, String idlength, String
gramsofgold, String Minimumcarattotalweight, String page, String
CategoryKey, String Width, String Numberofdiamonds) in
C:\Market\Components\MaintenanceDB.vb:1867
Market.__MaintProducts.updatecommandheader(Object sender,
DataGridCommandEventArgs H) in C:\Market\_MaintProducts.ascx.vb:531

System.Web.UI.WebControls.DataGrid.OnUpdateCommand (DataGridCommandEventA
rgs e) +109
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(O bject source,
EventArgs e) +507
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
+26
System.Web.UI.WebControls.DataGridItem.OnBubbleEve nt(Object source,
EventArgs e) +100
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
+26
System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e)
+120

System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler
.RaisePostBackEvent(String eventArgument) +115
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
+138
System.Web.UI.Page.ProcessRequestMain() +1258

Stanley J. Mroczek

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #3

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

Similar topics

4
by: Nicolas Fleury | last post by:
Hi, I've made a small utility to re-raise an exception with the same stack as before with additional information in it. Since I want to keep the same exception type and that some types have very...
1
by: Old Wolf | last post by:
1. What is the difference between #include <stdexcept> and #include <exception> ? 2. Is there a list somewhere of what each standard exception is used for? either to throw them, or throw...
11
by: Master of C++ | last post by:
Hi, I am writing a simulation package in C++, and so far I've written about 8000 lines of code and have about 30 classes. I haven't used C++ exceptions so far (for various reasons). The only two...
4
by: maricel | last post by:
I have the following base table structure - DDL: CREATE TABLE "ADMINISTRATOR"."T1" ( "C1" INTEGER NOT NULL ) IN "TEST_TS" ; ALTER TABLE "ADMINISTRATOR"."T1" ADD PRIMARY KEY
44
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level...
40
by: Kevin Yu | last post by:
is it a bad programming design to throw exception in the try block then catch it??
6
by: Vadivel Kumar | last post by:
I've a problem in handling a custom exception The following is my custom exception class: public class AppException : public Exception { public AppException (string message, Exception...
3
by: JohnDeHope3 | last post by:
First let me say that I understand that Asp.Net wraps my exception in an HttpUnhandledException. I have found a lot of discussion about that on the web, which was informative, but not helpful. Let...
7
by: Sek | last post by:
Hi Folks! I was pondering over a code and noticed that exception handlers were present in the private, protected as well as public methods. And, ofcourse, public methods were calling priv/prot...
2
by: Darko Miletic | last post by:
Recently I wrote a dll in c++ and to simplify the distribution I decided to link with multithreaded static library (/MT or /MTd option). In debug everything works fine but in release I get this: ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
Oralloy
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.