代码如下:
procedure TfmMain.LoginADatabase;
var
Reg:TRegistry;
begin
Reg:=TRegistry.Create;
try
Reg.RootKey:=HKEY_LOCAL_MACHINE;
if Reg.KeyExists('\SOFTWARE\NEWPIN\Test\') then
begin
if Reg.OpenKey('\SOFTWARE\NEWPIN\Test\',false) then
begin
if Reg.ReadString('Connection')='Use Windows authentication' then
try
ADOConnection1.Close;
ADOConnection1.ConnectionString:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog='+Reg.ReadString('Database Name')+';Data Source='+Reg.ReadString('SQLServer Name');
ADOConnection1.Open();
ADOConnection1.KeepConnection:=true;
except
if MessageDlg('服务器连接失败!'+#13+'请检查服务器是否处于运行状态或重新填写服务器登录信息。'+#13+#13+'是否重新填写服务器注册信息?',mtWarning,[mbYES,mbNO],0)=mrYES then
begin
RegASQL:=TRegASQL.Create(Application);
RegASQL.ShowModal;
RegASQL.Update;
end
else
Application.Terminate;
end;
if Reg.ReadString('Connection')='Use SQL Server authentication' then
try
ADOConnection1.Close;
ADOConnection1.ConnectionString:='Provider=SQLOLEDB.1;Password='+RegASQL.UnEncrypt(Reg.ReadString('Password'))+';Persist Security Info=True;User ID='+RegASQL.UnEncrypt(Reg.ReadString('User ID'))+';Initial Catalog='+Reg.ReadString('Database Name')+';Data Source='+Reg.ReadString('SQLServer Name');
ADOConnection1.Open();
ADOConnection1.KeepConnection:=true;
except
if MessageDlg('服务器登陆失败,是否重新注册?',mtWarning,[mbYES,mbNO],0)=mrYES then
begin
RegASQL:=TRegASQL.Create(Application);
RegASQL.ShowModal;
RegASQL.Update;
end
else
Application.Terminate;
end;
end;
end
else
begin
RegASQL:=TRegASQL.Create(Application);
RegASQL.ShowModal;
RegASQL.Update;
end;
finally
Reg.Free;
end;
end;
谢谢.我必有重谢的
procedure TfmMain.LoginADatabase;
var
Reg:TRegistry;
begin
Reg:=TRegistry.Create;
try
Reg.RootKey:=HKEY_LOCAL_MACHINE;
if Reg.KeyExists('\SOFTWARE\NEWPIN\Test\') then
begin
if Reg.OpenKey('\SOFTWARE\NEWPIN\Test\',false) then
begin
if Reg.ReadString('Connection')='Use Windows authentication' then
try
ADOConnection1.Close;
ADOConnection1.ConnectionString:='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog='+Reg.ReadString('Database Name')+';Data Source='+Reg.ReadString('SQLServer Name');
ADOConnection1.Open();
ADOConnection1.KeepConnection:=true;
except
if MessageDlg('服务器连接失败!'+#13+'请检查服务器是否处于运行状态或重新填写服务器登录信息。'+#13+#13+'是否重新填写服务器注册信息?',mtWarning,[mbYES,mbNO],0)=mrYES then
begin
RegASQL:=TRegASQL.Create(Application);
RegASQL.ShowModal;
RegASQL.Update;
end
else
Application.Terminate;
end;
if Reg.ReadString('Connection')='Use SQL Server authentication' then
try
ADOConnection1.Close;
ADOConnection1.ConnectionString:='Provider=SQLOLEDB.1;Password='+RegASQL.UnEncrypt(Reg.ReadString('Password'))+';Persist Security Info=True;User ID='+RegASQL.UnEncrypt(Reg.ReadString('User ID'))+';Initial Catalog='+Reg.ReadString('Database Name')+';Data Source='+Reg.ReadString('SQLServer Name');
ADOConnection1.Open();
ADOConnection1.KeepConnection:=true;
except
if MessageDlg('服务器登陆失败,是否重新注册?',mtWarning,[mbYES,mbNO],0)=mrYES then
begin
RegASQL:=TRegASQL.Create(Application);
RegASQL.ShowModal;
RegASQL.Update;
end
else
Application.Terminate;
end;
end;
end
else
begin
RegASQL:=TRegASQL.Create(Application);
RegASQL.ShowModal;
RegASQL.Update;
end;
finally
Reg.Free;
end;
end;
谢谢.我必有重谢的
解决方案 »
- delphi udpserver peerPort
- treeview 选中后显示的问题
- 我发现最近Delphi版来了不少穿小内裤的Java 粉丝
- 怎么样根据数据库中的单价画出走势图?
- DELPHI5(ADO) + SQL2000 ,主從表﹐刪除后的保存提交問題 !!!
- 公布一个秘籍,关于这方面有分的别忘记了让我拿哟。
- 再次求救:请教一个dbgrid的问题
- 在Delphi6中,如何将MaskEdit控件的EditMast属性中添加'/'字符,并在TEXT的显示时,TEXT文本上有一'/'
- 如何复制字符串?
- delphi中,为什么dbgrid不能显示memo字段里的内容.
- 大家来看看,up者有分。(数据库问题,大家帮帮忙,急用!)
- 怎样才能将任何字符串format为定长的字符串(在左边添加空格)?
to baby19820917()
没有搞错吧!自己写的代码让别人给注解?
主要就是从注册表中读取数据库联接的字符串进行数据联接!
其实这段代码还应该改造一下,就是如果注册表中没有该键值或者注册表中的键值不正确(根据注册表中的字符无法联接到数据库)时都应该让用户进行手工输入联接字符串,如果输入的字符串能正联接数据则应该写入到注册表中!