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;