我写的一个测试线程访问数据库的代码  但是OPEN的时候 报错  不知道如何解决  忘各位大侠指点
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DB, ADODB;type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }  public
    { Public declarations }
  end;  TDBExtractThread = class(Tthread)
  private
  protected
    procedure Execute; override;
  end;  TRunInfo = record
    AccessConn: TadoConnection;
    AccessQuery1 : TadoQuery;
    thread: TDBExtractThread;
  end;
var
  Form1: TForm1;
  threadsRunInfos: array[0..9] of TRunInfo;
implementation{$R *.dfm}{ TDBExtractThread }procedure TDBExtractThread.Execute;
begin
  with threadsRunInfos[0].AccessQuery1 do
  begin
    close;
    sql.Clear;
    sql.Add('select * from vehicle');
    open;
  end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
  threadsRunInfos[0].AccessConn := TadoConnection.Create(nil);
  threadsRunInfos[0].AccessConn.ConnectionString :='Provider=OraOLEDB.Oracle.1;Password=oracleadmin;Persist Security Info=True;User ID=veh_admin;Data Source=orcl' ;
  threadsRunInfos[0].AccessConn.LoginPrompt := False;
  threadsRunInfos[0].AccessConn.Connected := true;
  threadsRunInfos[0].AccessQuery1 := TadoQuery.Create(nil);
  threadsRunInfos[0].AccessQuery1.connection := threadsRunInfos[0].AccessConn;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
  threadsRunInfos[0].thread:=TDBExtractThread.Create(false);
end;end.

解决方案 »

  1.   

    open的时候 报 ‘未指定错误’
      

  2.   

    procedure   TDBExtractThread.Execute; 
    begin
        //在线程里使用ADO,请添加此代码
        //--begin--
        CoInitializeEx(nil, COINIT_MULTITHREADED);
        try 
       
        //--end----
     
        //在线程里可能会产生异常,请添加此代码
        //--begin--
        try    
        //--end----    with   threadsRunInfos[0].AccessQuery1   do 
        begin 
            close; 
            sql.Clear; 
            sql.Add('select   *   from   vehicle'); 
            open; 
        end;    //在线程里可能会产生异常,请添加此代码
        //--begin--
        except
          on E:Exception do
            begin

              //经这里记录错误日志
            end;
        end;
        
        //--end----    //在线程里使用ADO,请添加此代码
        //--begin--
        finally
          CoUninitialize;
        end;
     
        //--end----
     
    end; 
      

  3.   

    把错误信息贴出来
    ===============
    请看4楼“未知错误”,通常会产生于第三方COM服务当中。