Solved

VB.NET SQLException not falling into Catch block

Posted on 2007-11-26
5
1,516 Views
Last Modified: 2013-11-26
I am using the following code to update a database record:

                    Try

                        Dim intEditRow = gvExpenseCategory.EditIndex
                        Dim NewGLAccountCode As TextBox = gvExpenseCategory.Rows(intEditRow).FindControl("txtGLAccountCodeEdit")
                        strAccountCode = StrConv(Trim(NewGLAccountCode.Text & " "), VbStrConv.Uppercase)

                        Dim NewCategory As DropDownList = gvExpenseCategory.Rows(intEditRow).FindControl("ddCategoryEdit")
                        strCategory = NewCategory.Text

                        Dim NewDescription As TextBox = gvExpenseCategory.Rows(intEditRow).FindControl("txtDescriptionEdit")
                        strDescription = StrConv(Trim(NewDescription.Text & " "), VbStrConv.ProperCase)

                        Dim chkActive As CheckBox = gvExpenseCategory.Rows(intEditRow).FindControl("chkActiveEdit")
                        bActive = chkActive.Checked

                        .UpdateParameters("GLAccountCode").DefaultValue = strAccountCode
                        .UpdateParameters("Category").DefaultValue = strCategory
                        .UpdateParameters("Description").DefaultValue = strDescription
                        .UpdateParameters("ActiveFlag").DefaultValue = bActive
                        .UpdateParameters("LastUpdateBy").DefaultValue = sUserName
                        .UpdateParameters("LastUpdateDate").DefaultValue = Now()
                        .Update()
                    Catch SQLExp As SqlException
                        If SQLExp.Number = 1212 Then
                            Response.Write("SQL Server Error 1212 Occurred: " & e.ToString())
                        Else
                            Stop
                            'error handling
                        End If

                    End Try

It's throwing a SQLException error on the page:

Exception Details: System.Data.SqlClient.SqlException: Violation of UNIQUE KEY constraint 'IX_t_ExpenseCategory'. Cannot insert duplicate key in object 'dbo.t_ExpenseCategory'.
The statement has been terminated.

It just won't fall into the catch block and I can't figure out why.  

Thanks in advance,

N
0
Comment
Question by:stretch73
5 Comments
 
LVL 15

Expert Comment

by:spprivate
ID: 20353684
Catch it as general exception instead of SQL Exception and see what is the type of exception
0
 
LVL 18

Expert Comment

by:jcoehoorn
ID: 20353906
Details carried over from previous question:  The type of exception is SQLException.  It also won't stop on his breakpoints.
0
 
LVL 24

Accepted Solution

by:
Jeff Certain earned 500 total points
ID: 20354140
Can I ask the silly question about whether you're running in release or debug mode?
0
 

Author Comment

by:stretch73
ID: 20357576
Chaosian,

Not silly at all.  I'm pretty sure we're running in debug mode.
0
 
LVL 15

Expert Comment

by:spprivate
ID: 20362259
May I know what is the issue.If you are running in debug mode,what is the accepted solution?
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question