1、通過IP連接局域網共享Access資料庫,用TADOConnection建立連接,在屬性中ConnectionString添加地址和檔案不出錯,而清空后在資料模塊寫代碼報錯,不知什么原因

2、在資料模塊代碼不認application.MessageBox和showmessage?
procedure TDm1.DataModuleCreate(Sender: TObject);
var
condbstr: string;
path, datapath: string;
s, s1: string;
F: TextFile; //TextFile 和 Text 是一樣的
FileName: string;
begin
FileName := ExtractFilePath(Paramstr(0)) + '\data\test.txt'; //取得txt檔案的路徑
if fileExists(FileName) then //判斷檔案是否存在
begin
AssignFile(F, FileName);
Reset(F); //只讀打開
Readln(F, s); //讀取 IP第一行
s1 := s;
datapath := '\\' + s1 + '\kao$\'; // IP共享路徑
path := datapath + 'sjgl1.mdb'; // 獲取檔案
con1.Close;
con1.Connected := False; //關閉驗證
try
condbstr := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=path;Persist Security Info=False';
con1.ConnectionString := condbstr;
con1.Open;
con1.LoginPrompt := False;
con1.Connected := true;
except
con1.Close;
con1.Free;
// showmessage('不能連接到資料庫!') ;
//application.MessageBox('不能連接到資料庫!', '提示資訊', 64);
// application.Terminate;
end;
end
else
// Application.ShowException('沒有這個檔案');
end;
uj5u.com熱心網友回復:
condbstr := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=path;Persist Security Info=False';這句有問題,改成
condbstr := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+path+';Persist Security Info=False';
uj5u.com熱心網友回復:
condbstr := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source= path;Persist Security Info=False';uj5u.com熱心網友回復:
condbstr := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+path+';Persist Security Info=False';uj5u.com熱心網友回復:
謝謝,真是condbstr := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source= path;Persist Security Info=False';這出錯,改為condbstr := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+path+';Persist Security Info=False';就連接上了,那為什么在資料模塊上用application.MessageBox、showmessage和Application.ShowException和ShowException不認uj5u.com熱心網友回復:
condbstr :=format('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;Persist Security Info=False',[path]);
uj5u.com熱心網友回復:
path := datapath + 'sjgl1.mdb'; // 獲取檔案
con1.Connected := False; //關閉驗證
try
condbstr :=format('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;Persist Security Info=False',[path]);
con1.ConnectionString := condbstr;
con1.LoginPrompt := False;
con1.Connected := true;
except
con1.Close;
end;
uj5u.com熱心網友回復:
application.MessageBox、showmessage和Application.ShowException這些不能用,如IP或檔案名錯誤,就沒地方提示,最后還是會報錯“missing Connection or ConnectionString”轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/274262.html
標籤:數據庫相關
