Home » U++ Library support » U++ SQL » MSSQL error management
MSSQL error management [message #49477] |
Fri, 16 February 2018 10:36 |
Giorgio
Messages: 218 Registered: August 2015
|
Experienced Member |
|
|
Hi there,
to execute SQL queries I use code like this:
bool ImportData::InsertBody(myS_Table record)
{
Sql sql(mssql);
sql.ClearError();
try { sql * Insert(My_Table)
(My_Id, record.Id)
(My_Row, record.Row)
(My_Description, record.Description);
return true;
} catch(SqlExc) {
ErrorOK(t_("Failed adding data to the database due to the following error: ") + SQL.GetLastError());
return false;
}
return true;
}
In this way, (1) if there are errors in executing the query the user is notified of the specific reason and (2) I can control the program flow using the true/false value returned by the method.
This is working as expected for MySql, PostgreSql and SQLite, but here it comes Microsoft and its @#!&$ MS Sql Server.
When there is an error (e.g. a duplicate key) the user is NOT notified and the query returns always true. The only way to catch errors is looking at the log file activated using .LogErrors() and SetTrace(). This is not really user friendly. In case of an error what I got in the log file is the following:
ERROR [Microsoft][SQL Server Native Client 11.0][SQL Server]Violation of PRIMARY KEY constraint 'Id'. Cannot insert duplicate key in object 'dbo.X_DORIG'. The duplicate key value is (180107, 1, 'Art. number' ).(0): insert into X_DORIG(Id, Row, Description,) values (180107, 1, 'Art. number')
I tried using both Driver={SQL Server Native Client 11.0}; and Driver={SQL Server}; with the same result.
Is there a workaround for this issue?
Thanks,
Gio
[Updated on: Fri, 16 February 2018 10:36] Report message to a moderator
|
|
|
|
|
MSSQL error management
By: Giorgio on Fri, 16 February 2018 10:36
|
|
|
Re: MSSQL error management
By: mirek on Sat, 24 February 2018 19:21
|
|
|
Re: MSSQL error management
By: mirek on Sat, 24 February 2018 19:39
|
|
|
Re: MSSQL error management
By: Giorgio on Mon, 26 February 2018 15:01
|
|
|
Re: MSSQL error management
By: mirek on Mon, 26 February 2018 16:22
|
|
|
Re: MSSQL error management
By: Giorgio on Fri, 09 March 2018 18:40
|
|
|
Re: MSSQL error management
By: mirek on Wed, 14 March 2018 10:39
|
|
|
Re: MSSQL error management
By: Giorgio on Mon, 19 March 2018 12:40
|
|
|
Re: MSSQL error management
By: mirek on Mon, 19 March 2018 12:58
|
|
|
Re: MSSQL error management
By: Giorgio on Mon, 19 March 2018 14:50
|
|
|
Re: MSSQL error management
By: mirek on Mon, 19 March 2018 16:35
|
|
|
Re: MSSQL error management
By: Giorgio on Tue, 20 March 2018 11:15
|
|
|
Re: MSSQL error management
By: mirek on Tue, 20 March 2018 16:42
|
|
|
Re: MSSQL error management
By: Giorgio on Wed, 21 March 2018 13:14
|
|
|
Re: MSSQL error management
By: mirek on Wed, 21 March 2018 14:41
|
|
|
Re: MSSQL error management
By: mirek on Wed, 21 March 2018 15:25
|
|
|
Re: MSSQL error management
By: Giorgio on Wed, 21 March 2018 15:58
|
|
|
Re: MSSQL error management
By: mirek on Wed, 21 March 2018 16:14
|
|
|
Re: MSSQL error management
By: Giorgio on Wed, 21 March 2018 16:30
|
|
|
Re: MSSQL error management
By: mirek on Wed, 21 March 2018 18:46
|
|
|
Re: MSSQL error management
By: Giorgio on Thu, 22 March 2018 09:06
|
Goto Forum:
Current Time: Thu Oct 31 23:47:43 CET 2024
Total time taken to generate the page: 0.02033 seconds
|