473,385 Members | 1,397 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Catch primary key violation exception in Visual Basic 2003

I searched online and went through the forums as well, but i could not
find a way to capture the database primary key violation exception.
Any help will be much appreciated.

Thanks,
Hetal

Sep 12 '07 #1
2 3198
Hi Armin,

Thank you for your response.

I do have a try catch block in place and the exception occurs when my
insert statement violates a priimary key. This is how the catch block
looks like.

===========
Catch ex As Exception
If ex.InnerException Is Nothing Then
Log("*** Schedule.CreateShifts() Error occured. - " &
ex.Message)
Else
Log("*** Schedule.CreateShifts() Error occured. - " &
ex.InnerException.Message)
End If
==========

and the error message i am receiving is:

"ERROR [23000] [MySQL][ODBC 3.51 Driver][mysqld-5.0.21-community-
nt]Duplicate entry '2007-09-17 00:00:00-9-1' for key 1"

My question is, how can i single out this particular exception in my
catch block? As i will be performing a different set of activity for
primary key violations and for any other exceptions, i will just be
logging them in a log file.

Thanks,
Hetal.

Sep 12 '07 #2
Hetal,

The answer is simple, don't use primary keys for outside database use. There
are always two identifiers, one for the humans and one for the database. In
that case you cannot have any conflict. Identifiers types can be: automatic
idents which are integers or Guids, the later is prefered, because those you
can manage yourself.

If you want to use the identifier outside the database as well, then first
let the database create that one (not a Guid that is for humans unusable)
and show that to the user. I find that a very bad solution because you are
by instance dependend on what exist and what is deleted.

Cor

"Hetal" <he*************@gmail.comschreef in bericht
news:11**********************@57g2000hsv.googlegro ups.com...
>I searched online and went through the forums as well, but i could not
find a way to capture the database primary key violation exception.
Any help will be much appreciated.

Thanks,
Hetal
Sep 13 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Brian | last post by:
I have a vb.net application which runs fine when installed locally on a user machine but when the application is run from a network drive a security exception error occurs. I've set the intranet...
0
by: PleaseNOSpam4Me | last post by:
I have a few SEALED copies of Visual Basic .NET Deluxe 2003 and a few 2002 versions as well if anyone wants them. It comes with the full Visual Basic 2003 Standard Edition and the Step by Step...
2
by: frossberg | last post by:
Hello! I tried to install the Visual Basic.NET Resource Kit (http://msdn.microsoft.com/vbasic/vbrkit/) but obviously something went very wrong and now it sems impossible both to repair and to...
0
by: Betinho | last post by:
And after the installing of 2005 Beta 1, I got in problems because the GUI are not loadings and I can not use the program because the toolbox are not working eaither and the program hold still...
0
by: MirkoGeest | last post by:
(Webmaster: sorry, I posted this first at the General Software Engineering category, but I think this goes here) I'm using Visual Basic with Web Forms on .NET 2003 and I'm experiencing a very...
2
by: John.Miller | last post by:
I am writing an application inVisual Studio to ease our frontpage publishes. I have the command to publish, but I need to attach the Publish log to an email. Does anyone know how to get the...
6
by: Carol | last post by:
Hi. When I try to run Visual Studio 2003 I get the message "MS development environment is not installed for the current user. Please run setup to install the application." Is there any way to...
1
by: codeman54 | last post by:
I have Visual Basic 2003. We are working on a project to create a game in our class. Can any one help?
1
by: nathaniel14 | last post by:
Lend a hand I am trying to install visual basic 2003 in my laptop . I keeping getting this message "Setup was unable to find the Baseline data ". Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.