?
Solved

VB.NET SQLException not falling into Catch block

Posted on 2007-11-26
5
Medium Priority
?
1,524 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

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