在多线程处理数据库时,肯定要用到TSession,
不同的SessionName代表多线程,所以AutoSessionName要设为False;
再自己写一个区别SessionName的函数进行调用;

解决方案 »

  1.   

    在多线程处理数据库时,肯定要用到TSession,
    不同的SessionName代表多线程,所以AutoSessionName要设为False;
    再自己写一个区别Session
      

  2.   

    keboy,thank you!
    但是如何使用Tsession,在线程代码里为每一个存储过程指定呢?还是在父程序中?
    能给个简单的例子吗?我一定将200分献上!
      

  3.   

    谁能给个简单的例子吗?我一定将200分献上! 
    -如何使用Tsession,在线程代码里为每一个存储过程指定呢?还是在父程序中?
    能给个简单的例子吗?
      

  4.   

    TSampleThread = class(TThread)
    TSampleThread.Create(Session:TSession; ASP:TStoreProc;Askt:TCustomWinSocket);
    begin
      inherited create(false);  
      ASP.sessionname:= session.sessionname;
      ....
    end;
    另外,你的错误与线程无关,是你激活ASP:TStoreProc使用的是open, 而StoreProc可能有错误没有返回值,所以才会报错:'Error creating cursor handle'. 我以前碰到类似问题,你最好再仔细检查一下
      

  5.   

    dragongong,Thanks for your help!
    But I can be sure there are some records rerurned!
    when I use the single thread,It run properly!
    So,Please give a simple sample for using multi thread to deal with database
    storedProc!
      

  6.   

    sorry, I'm so busy recently. now give you a quite simple sample. enjoy!unit threadunit;interfaceuses classes, stdctrls, sysutils, dbtables, forms;type
      TSampleThread = class(TThread)
      private
        { Private declarations }
        FSP:TStoredProc;
        FMemo:TMemo;
        FSession:TSession;
        FThreadDBException: Exception;
      protected
        procedure Execute; override;
        procedure show;
        procedure showError;
      public
        constructor Create(sp:TStoredProc;M:TMemo);
      end;
    implementation{ TSampleThread }constructor TSampleThread.Create(sp: TStoredProc; M: TMemo);
    begin
      inherited create(true);
      Fsession:= TSession.create(Application);
      FSP:= sp;
      FMemo:= M;
      FreeOnTerminate := True;
      resume;
    end;procedure TSampleThread.Execute;
    begin
      try
        FSP.open;
        show; // here needn't use synchronize because synchronize procedure is run in the VCL main thread.
      except
        FThreadDBException := Exceptobject as Exception;
        synchronize(show);
      end;
    end;procedure TSampleThread.show;
    begin
      Fsp.first;
      while not Fsp.eof do
      begin
        FMemo.Lines.Add(FSP.Fields[0].asstring);
        Fsp.next;
      end;
    end;procedure TSampleThread.showError;
    begin
      Application.showexception(FThreadDBException);
    end;end.
      

  7.   

    sorry, i'm very busy recently. now give you a quite simply sample .unit threadunit;interfaceuses classes, stdctrls, sysutils, dbtables, forms;type
      TSampleThread = class(TThread)
      private
        { Private declarations }
        FSP:TStoredProc;
        FMemo:TMemo;
        FSession:TSession;
        FThreadDBException: Exception;
      protected
        procedure Execute; override;
        procedure show;
        procedure showError;
      public
        constructor Create(sp:TStoredProc;M:TMemo);
      end;
    implementation{ TSampleThread }constructor TSampleThread.Create(sp: TStoredProc; M: TMemo);
    begin
      inherited create(true);
      Fsession:= TSession.create(Application);
      FSP:= sp;
      FMemo:= M;
      FreeOnTerminate := True;
      resume;
    end;procedure TSampleThread.Execute;
    begin
      try
        FSP.open;
        show; // here needn't use synchronize because synchronize procedure is run in the VCL main thread.
      except
        FThreadDBException := Exceptobject as Exception;
        synchronize(showerror);
      end;
    end;procedure TSampleThread.show;
    begin
      Fsp.first;
      while not Fsp.eof do
      begin
        FMemo.Lines.Add(FSP.Fields[0].asstring);
        Fsp.next;
      end;
    end;procedure TSampleThread.showError;
    begin
      Application.showexception(FThreadDBException);
    end;end.
      

  8.   

    Thanks for your kind help!
      

  9.   

    dragongong,you have been very helpful!
    I want to give you 200,but it dose not work!
    Maybe I am a jounor user of this web!
    I only can give you 107 which is full  of this question!
    Thanks again!
      

  10.   

    It's my pleasure! Keeping touch.