L
lixin38
Unregistered / Unconfirmed
GUEST, unregistred user!
把數據從Access--->SQL中,參考了這裡代碼http://www.delphibbs.com/delphibbs/dispq.asp?lid=1691966
但我把程序改為線程來執行卻出現了錯誤,錯誤信息如下:CoInitialize 尚未被呼叫。
窗體上就一個ADOConnection,兩個Button,
代碼很簡單就如下幾行:
procedure ExportData;
begin
try
Screen.Cursor:=crSQLWait;
try
Form1.ADOConnection1.ConnectionString:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=Test;Data Source=PServer';
//下面這行就是出問題的地方
Form1.ADOConnection1.Execute('Insert into [MyAccess] SELECT * FROM OpenDataSource( '
+QuotedStr('Microsoft.Jet.OLEDB.4.0')+','
+QuotedStr('Data Source="//PCName/IC/IOData.mdb";Persist Security Info=False;User ID=Admin;Password=;')+')...[IOData]');
except
on E:Exception do
Form1.Caption:=E.Message;
end;
finally
Screen.Cursor:=crDefault;
Form1.ADOConnection1.Connected:=False;
end;
end;
procedure TForm1.Btn_NoThreadClick(Sender: TObject);//不用線程的沒問題
begin
ExportData;
end;
{ TMyThread }
procedure TMyThread.Execute;
begin
ExportData;
end;
procedure TForm1.Btn_UseThreadClick(Sender: TObject);//用線程的,會有問題
begin
aThread:=TMyThread.Create(False);
end;
但我把程序改為線程來執行卻出現了錯誤,錯誤信息如下:CoInitialize 尚未被呼叫。
窗體上就一個ADOConnection,兩個Button,
代碼很簡單就如下幾行:
procedure ExportData;
begin
try
Screen.Cursor:=crSQLWait;
try
Form1.ADOConnection1.ConnectionString:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=Test;Data Source=PServer';
//下面這行就是出問題的地方
Form1.ADOConnection1.Execute('Insert into [MyAccess] SELECT * FROM OpenDataSource( '
+QuotedStr('Microsoft.Jet.OLEDB.4.0')+','
+QuotedStr('Data Source="//PCName/IC/IOData.mdb";Persist Security Info=False;User ID=Admin;Password=;')+')...[IOData]');
except
on E:Exception do
Form1.Caption:=E.Message;
end;
finally
Screen.Cursor:=crDefault;
Form1.ADOConnection1.Connected:=False;
end;
end;
procedure TForm1.Btn_NoThreadClick(Sender: TObject);//不用線程的沒問題
begin
ExportData;
end;
{ TMyThread }
procedure TMyThread.Execute;
begin
ExportData;
end;
procedure TForm1.Btn_UseThreadClick(Sender: TObject);//用線程的,會有問題
begin
aThread:=TMyThread.Create(False);
end;