Interruption exception using TSQLQuery & params

I get the error "SQL Server Error: Arithmetic Exception, Numeric Overflow, or Line Break Error" Error

here is the code below

AQuery:= TSQLQuery.Create(nil);
with AQuery do
begin
SQLConnection:- AConnection;
 SQL.Text:= 'Insert into.....';
 ParamByName('...').asString:= 'PCT';
 .
 .
 .

 try
  ExecSQL;
 finally
  AQuery.Free;
 end;
end;

I have many lines of ParamByName, and I cannot figure out which one throws an exception. I just know that it was thrown on the ExecSQL line. How can I determine which paramByName is causing the error?

+3
source share
4 answers

You are trying to insert a string value into a field that is not large enough to hold the value. Check the length of the inserted values ​​in relation to the length of the field in the table.

0

, . , parambynames. , . ( , varchars , )

+2

SQL param SQL Server.
.

+1

, . , .

ParamByName (''). AsString: = blah , :

ParamByName('surname').AsString:='Smith';
ParamByName('firstname').AsString:='John';

.., , . , , , , . , .

Depending on how much access (and experience) you have, it might be more useful to enable SQL Server logging so that you can see your queries (and the contents of these parameters) when the query is processed by the SQL server. This will show you which strings and numeric values ​​are actually being passed to the server. What version / version of SQL Server are you using?

0
source

Source: https://habr.com/ru/post/1720710/


All Articles