不一定是udl的问题,其他机上也试一下!
要不用这个
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB, Registry;
type
TForm1 = class(TForm)
Button1: TButton;
ADOConnection1: TADOConnection;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//动态选择数据源和数据库
procedure TForm1.Button1Click(Sender: TObject);
var
strConnection: string;
Reg01: TRegistry;
begin
strConnection := '';
Reg01 := Tregistry.Create;
try
//从注册表中读出ConnectionString
Reg01.RootKey := HKEY_CURRENT_USER;
if Reg01.OpenKey('/Software/LdcErpAcc/AdoCon', TRUE) then
strConnection := Reg01.ReadString('Connection');
adoconnection1.ConnectionString := strConnection;
try
adoconnection1.open;
except
adoconnection1.Close;
strConnection := PromptDataSource(Handle, ADOConnection1.ConnectionString);
showmessage(strConnection);
if strConnection <> '' then
begin
adoconnection1.ConnectionString := strConnection;
if (Reg01.OpenKey('/Software/LdcErpAcc/AdoCon', False)) = False then
//如果注册表中没有信息则创建信息
reg01.CreateKey('/Software/LdcErpAcc/AdoCon');
//将ConnectionString写到注册表中
Reg01.OpenKey('/Software/LdcErpAcc/AdoCon', True);
Reg01.WriteString('Connection', strConnection);
adoconnection1.Open;
end
else
Application.Terminate;
end;
finally
Reg01.closekey;
Reg01.free;
end;
end;
end.