通过IP连接局域网共享Access数据库出错,请高手帮我看看

oTianLong123456 2021-04-09 04:23:03
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;
...全文
470 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
oTianLong123456 2021-04-16
  • 打赏
  • 举报
回复
终于查到在数据模块不认的原因,在引用单元里增加Messages就行了,结贴
oTianLong123456 2021-04-09
  • 打赏
  • 举报
回复
application.MessageBox、showmessage和Application.ShowException这些不能用,如IP或文件名错误,就没地方提示,最后还是会报错“missing Connection or ConnectionString”
tanqth 2021-04-09
  • 打赏
  • 举报
回复

    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;

tanqth 2021-04-09
  • 打赏
  • 举报
回复

 condbstr :=format('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;Persist Security Info=False',[path]);
oTianLong123456 2021-04-09
  • 打赏
  • 举报
回复
谢谢,真是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不认
iswindy 2021-04-09
  • 打赏
  • 举报
回复
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';

天行归来 2021-04-09
  • 打赏
  • 举报
回复
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';

2,497

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧