我本来想在form.creat()事件里面判断是否数据库连接成功,但是它提示是说“验证失败”为什么??/帮我改一下!!
代码是:
procedure TForm1.FormCreate(Sender: TObject);
var
strConn:string;
/// t:integer;
ifok:boolean;
// str1:string;
//Winpath:pchar;
db:pchar;
myinifilepath:pchar;
begin
form1.ADOConnection1.Close;
form1.ADOConnection1.ConnectionTimeout :=1;
form1.ADOConnection1.CommandTimeout:=1;
// if dm.song_conn.Connected then exit;
ifok:=true;
getmem(db,225);
myinifilepath:=pchar(ExtractFilePath(paramstr(0))+'nsvod.ini');
GetPrivateProfileString('admin', 'db',nil,db,225,myinifilepath);
strconn:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+db+';Persist Security Info=true;Jet OLEDB:Database Password= ';
//form1.ADOConnection1.LoginPrompt:=false;
try
with form1.ADOConnection1 do
begin
Connected:=false;
ConnectionString:=strConn;
Connected:=true;
// addmemo('已正常联接主歌曲数据库');
end;
except
ifok:=false;
end;
if not ifok then
begin
ShowMessage('初始化时出错!,请卸载本系统后重新安装 ');
close;
exit;
end;end;
代码是:
procedure TForm1.FormCreate(Sender: TObject);
var
strConn:string;
/// t:integer;
ifok:boolean;
// str1:string;
//Winpath:pchar;
db:pchar;
myinifilepath:pchar;
begin
form1.ADOConnection1.Close;
form1.ADOConnection1.ConnectionTimeout :=1;
form1.ADOConnection1.CommandTimeout:=1;
// if dm.song_conn.Connected then exit;
ifok:=true;
getmem(db,225);
myinifilepath:=pchar(ExtractFilePath(paramstr(0))+'nsvod.ini');
GetPrivateProfileString('admin', 'db',nil,db,225,myinifilepath);
strconn:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+db+';Persist Security Info=true;Jet OLEDB:Database Password= ';
//form1.ADOConnection1.LoginPrompt:=false;
try
with form1.ADOConnection1 do
begin
Connected:=false;
ConnectionString:=strConn;
Connected:=true;
// addmemo('已正常联接主歌曲数据库');
end;
except
ifok:=false;
end;
if not ifok then
begin
ShowMessage('初始化时出错!,请卸载本系统后重新安装 ');
close;
exit;
end;end;
解决方案 »
- Timage图片截取问题,等待解决!
- select count语句的赋值问题~
- ExcelApp: Variant和ExcelApp:=CreateOleObject('Excel.application')这两句话一定要写在同一个过程里吗?
- 想找一个日历控件,当选择日期后能显示当天是什么生肖日,请各位帮忙,谢谢!
- 我要控件
- 如何作这样的组件?
- 2个MenuItem用一样的快捷键 为什么不行?
- 为什么我用指定值方式dbcombobox的值不能保存进表里?请各位帮忙
- 怎样用 worddocument组件在 w o r d中插入以副图片
- 怎样取出DBGRID中的所有行的某个字段的值!
- x信誉x 只见减 不知怎样+?
- 不好意思,一个非常非常菜的问题
function GetConnectionString(ssource,accesspwd: string): string;
begin
Result := '';
if ssource <> '' then
Result := 'Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;' +
'Data Source=' + sSource + ';User ID=Admin;Jet OLEDB:Database Password=' +
accesspwd;
end;
我用打包程序打包生成的setup文件,在安装以后无法找到数据库
而在本机是可以运行的
这是为什么????????????????????????????????????????????????????????????????????????//
我用打包程序打包生成的setup文件,在安装以后无法找到数据库
而在本机是可以运行的
这是为什么????????????????????????????????????????????????????????????????????????//
我用打包程序打包生成的setup文件,在安装以后无法找到数据库
而在本机是可以运行的
这是为什么????????????????????????????????????????????????????????????????????????//
路径和安装后存放的路径不一样
2、你的INI文件里面有没有初始的地址?
2、觉得你的代码多是无用代码,而且不免清晰,如果只是有ACCESS的话,我觉得完
全可以用".\数据库名"来指定数据库
太小了吧 改成0试试
改成:
strconn:='Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;' +
'Data Source=' + sSource + ';User ID=Admin;Jet OLEDB:Database Password=' +
accesspwd;
跟踪一下 看看他的实际值是什么,尤其是db的值,如果没有问题就把Password=后边的空格去掉试试
我用打包程序打包生成的setup文件,在安装以后无法找到数据库
而在本机是可以运行的
这是为什么????????????????????????????????????????????????????????????????????????//
var
sconstr:string;
sdbpath:string;
smm:string;
begin
smm:='newspace0411';
try
G_StrExePath:=ExtractFilePath(Application.ExeName);
sdbpath:=G_StrExePath+'AA67.mdb';
sconstr:='Provider=Microsoft.Jet.OLEDB.4.0;'+
'User ID=Admin;Data Source='+sdbpath+';'+
'Mode=Share Deny None;Extended Properties="";'+
'Locale Identifier=2052;Persist Security Info=False;'+
'Jet OLEDB:System database="";Jet OLEDB:Registry Path="";'+
'Jet OLEDB:Database Password='+smm+';'+
'Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=0;'+
'Jet OLEDB:Global Partial Bulk Ops=2;'+
'Jet OLEDB:Global Bulk Transactions=1;'+
'Jet OLEDB:New Database Password="";'+
'Jet OLEDB:Create System Database=False;'+
'Jet OLEDB:Encrypt Database=False;'+
'Jet OLEDB:Don''t Copy Locale on Compact=False;'+
'Jet OLEDB:Compact Without Replica Repair=False;'+
'Jet OLEDB:SFP=False';
if DM1.ADOCn1.Connected = True then DM1.ADOCn1.Connected:=False;
DM1.ADOCn1.ConnectionString:=sconstr;
DM1.ADOCn1.Connected:=True;
except
Application.MessageBox('ÎÞ·¨Á¬½ÓÊý¾Ý¿â£¡','´íÎó',MB_OK+MB_ICONSTOP);
Halt;
end;end;
'%s; Persist Security Info=True';
应该动态的获取数据库文件的路径才能保证在别的机器上能正确运行