试一试这种方法吧,可能你能用的着,该程序调试通过,能调用设置
数据连接的那个窗口,和udl的面一样。能返回连接字符串。
在uses 中添加 OLEDB,comObj,ActiveX 单元
procedure TForm1.Button2Click(Sender: TObject);
var
Str :WideString;
begin
Str := 'Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=XJTZF;Data Source=YGT';
Str := PromptDataSource(Handle, Str) ;
end;
function PromptDataSource(ParentHandle: THandle; InitialString: WideString): WideString;
var
DataInit: IDataInitialize;
DBPrompt: IDBPromptInitialize;
DataSource: IUnknown;
InitStr: PWideChar;
begin
Result := InitialString;
DataInit := CreateComObject(CLSID_DataLinks) as IDataInitialize;
if InitialString <> '' then
DataInit.GetDataSource(nil, CLSCTX_INPROC_SERVER,
PWideChar(InitialString), IUnknown, DataSource);
DBPrompt := CreateComObject(CLSID_DataLinks) as IDBPromptInitialize;
if Succeeded(DBPrompt.PromptDataSource(nil, ParentHandle,
DBPROMPTOPTIONS_PROPERTYSHEET, 0, nil, nil, IUnknown, DataSource)) then
begin
InitStr := nil;
DataInit.GetInitializationString(DataSource, True, InitStr);
Result := InitStr;
end;
end;