I have migrated from PostgreSQL 8.3 to PostgreSQL 9.3 in order to use the improvements implemented in this version. With version 8.2 I had no problem handling errors when trying to insert a duplicate record with unique key since the program (Visual Studio 2013 vb.net) received a message from PostgreSQL and acted accordingly with a TRY...CATCH
. But since I have migrated to 9.3, when doing a insert
, the program waits to receive a message from PostgreSQL 9.3 and does not continue. I attached example code:
Public Sub EjecutaComando(ByVal StringSql As String)
'Procedure básico para ejecutar Insert i Updates sin tenerlas que implementar en cada uno de los procesos
Dim data As New NpgsqlCommand
data.Connection = MiConexio
data.CommandText = StringSql
Try
AbrirConexion()
data.ExecuteNonQuery()
Catch ex As Exception
nada()
Finally
CerrarConexion()
data.Dispose()
End Try
End Sub
If the statement is insert
against a table with a unique key, the code stops at data.ExecuteNonQuery()
. I run the query from PgAdmin and it returns an error message of duplicate Key
. The Npgsql version I use is 2.012.0
.
Can someone enlighten me where the problem is?
According to this thread , your problem is definitely a bug in the version of Npsql you use (2.0.12.0).
Translating a part of the reference:
In your case, since version 2.x is already quite old, I suggest you update your Npsql with one of the most recent available versions and that should fix your problem.