Solved

VB.NET SQLException not falling into Catch block

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

Containers and Docker for Everyone

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

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…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

688 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