Solved

VB.NET SQLException not falling into Catch block

Posted on 2007-11-26
5
1,515 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

831 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