Solved

VB.NET SQLException not falling into Catch block

Posted on 2007-11-26
5
1,512 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
Comment Utility
Catch it as general exception instead of SQL Exception and see what is the type of exception
0
 
LVL 18

Expert Comment

by:jcoehoorn
Comment Utility
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
Comment Utility
Can I ask the silly question about whether you're running in release or debug mode?
0
 

Author Comment

by:stretch73
Comment Utility
Chaosian,

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

Expert Comment

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

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now