I'm running a query against a MySQL database, and its statement is simply
SELECT * FROM tableOperationsHistory;
However, it fails and I get this exception (I translated it into English):
Fail activating restrictions. One or more rows contain values that violate non-null, unique or foreign-key restrictions.
This is the routine where the error happens:
Public Function RetrieveTable(ByVal command_text As String, Optional ByVal parameters As ParameterSet = Nothing) As DataTable
Dim dt As New DataTable, retry = False
Do
Using comm = conn.CreateCommand
comm.CommandText = command_text
If parameters IsNot Nothing Then
Dim par As DbParameter
For Each pair In parameters
par = comm.CreateParameter
par.ParameterName = pair.Key
par.Value = pair.Value
comm.Parameters.Add(par)
Next
End If
Dim rdr As DbDataReader
RequestConnection()
Try
rdr = comm.ExecuteReader
dt.Load(rdr)
retry = False
Catch ex As Exception
retry = ShouldRetry(ex) 'EXCEPTION IS CAUGHT HERE
End Try
DismissConnection()
End Using
Loop While retry
Return dt
End Function
And this is the table definition statement:
CREATE TABLE `tableOperationsHistory` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`numero` varchar(45) DEFAULT NULL,
`pasta_id` int(11) DEFAULT NULL,
`dataHoraInicioPrazo` datetime DEFAULT NULL,
`dataHoraFinalPrazo` datetime DEFAULT NULL,
`urgente` tinyint(4) DEFAULT NULL,
`setorOrigem_id` int(11) DEFAULT NULL,
`unidade_id` int(11) DEFAULT NULL,
`setor_id` int(11) DEFAULT NULL,
`usuario_id` int(11) DEFAULT NULL,
`modalidadeComunicacaoJudicial_id` int(11) DEFAULT NULL,
`modalidadeRepercussao_id` int(11) DEFAULT NULL,
`especieTarefa_id` int(11) DEFAULT NULL,
`postIt` varchar(255) DEFAULT NULL,
`teor_observacao` varchar(255) DEFAULT NULL,
`comunicacaoJudicial_id` int(11) DEFAULT NULL,
`tarefa_id` int(11) DEFAULT NULL,
`mensagens` text,
`criadoPor_id` int(11) DEFAULT NULL,
`criadoEm` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=92 DEFAULT CHARSET=latin1;
How can this happen in a SELECT statement? What should I do?