View Single Post
  #1  
Old 10-21-2016, 06:35 AM
ShaunVW ShaunVW is offline
Member
 
Join Date: Feb 2012
Posts: 47
Default TADOQuery crashing on open in thread

What used to run fine is now crashing, and I can't seem to figure out why.
I have placed the TQuery (of type TADOQuery) in a try/except block, but it never gets to the except part.
When I single step it, I can get it all the way to a procedure in Data.Win.ADODB as per the below:

Code:
 
procedure TADOCommand.OpenConnection;
begin
  if not Assigned(CommandObject.Get_ActiveConnection) then
  begin
    if ConnectionString <> '' then
      CommandObject._Set_ActiveConnection(FConnectionString)
    else if Assigned(FConnection) then
    begin
      FConnection.CheckActive;
      CommandObject.Set_ActiveConnection(FConnection.ConnectionObject);
    end else
      DatabaseError(SMissingConnection);
  end;
end;
I can't get it further than the line
CommandObject._Set_ActiveConnection(FConnectionStr ing)

When I F7/single step it from this line, it goes to the procedure in Systems.Variants as per below:
Code:
 
procedure _VarFromWStr(var V: TVarData; const Value: WideString);
begin
  if (V.VType and varDeepData) <> 0 then
    VarClearDeep(V);
  V.VOleStr := nil;
  V.VType := varOleStr;
  WideString(Pointer(V.VOleStr)) := Copy(Value, 1, MaxInt);
end;
However, it processes each of these lines fine, gets to the final 'end', and then crashes, so I'm not sure how to find the reason.

I have previously had a problem like this, and someone said to include a
TQuery.ParamCheck := False;
which I have done, but it still crashes.

This is my procedure in the thread...

Code:
 
var
 TQuery : TADOQuery;
 query : String;
 i : Integer;
begin
 CoInitialize(nil);
 TQuery := TADOQuery.Create(nil);
 TQuery.ConnectionString := 'FILE NAME=c:\ProductionDB\MP2.udl';
 TQuery.ParamCheck := FALSE;
 query := 'SELECT empcode, firstname, lastname, socsecnum, hiredate, description, costcenter FROM emp ' +
          'LEFT JOIN dept ON emp.department = dept.department';
 TQuery.SQL.Clear;
 TQuery.SQL.Add(query);
 i := 0;
 try
  TQuery.Open;
 except
  i := 9; //used just so I can single step to this line
 end;
....