Програмное создание нового DSN


type  
TSQLConfigDataSource =  
function(hwndParent: Integer;  
fRequest: Integer;  
lpszDriverString: string;  
lpszAttributes: string): Smallint; stdcall;  
  
function SQLConfigDataSource(hwndParent: Integer; fRequest: Integer;  
lpszDriverString: string; lpszAttributes: string): Integer; stdcall;  
var  
func: TSQLConfigDataSource;  
OdbccpHMODULE: HMODULE;  
  
begin  
OdbccpHMODULE := LoadLibrary(′c:WINDOWSSYSTEModbccp32.dll′);  
if OdbccpHMODULE = 0 then  
raise Exception.Create(SysErrorMessage(GetLastError));  
func := GetProcAddress(OdbccpHMODULE, PChar(′SQLConfigDataSource′));  
if @func = nil then  
raise Exception.Create(′Error Getting adress for SQLConfigDataSource′ +  
SysErrorMessage(GetLastError));  
Result := func(hwndParent, fRequest, lpszDriverString, lpszAttributes);  
FreeLibrary(OdbccpHMODULE);  
end;  
  
procedure TForm1.Button1Click(Sender: TObject);  
begin  
if SQLConfigDataSource(0, 1, ′Microsoft Excel Driver (*.xls)′,  
Format(′DSN=%s;DBQ=%s;DriverID=790′, [′MyDSNName′,  
′c: emp emp.xls′])) <> 1 then  
ShowMessage(′Cannot create ODBC alias′);  
end;   
Теги:
DSN
Добавлено: 30 Июля 2018 20:21:36 Добавил: Андрей Ковальчук Нравится 0
Добавить
Комментарии:
Нету комментариев для вывода...