Re: trouble creating DSN



So I decided to just wirte to the registry. It's easier. Here's what I did
in case anyone else needs the info:

procedure TForm1.Button1Click(Sender: TObject);
var
Reg: TRegistry;
begin

Reg := TRegistry.Create;
try

with Reg do
begin
RootKey := HKEY_LOCAL_MACHINE;
OpenKey('Software\ODBC\ODBC.INI\Keiths Test DSN', True);
WriteString('Database', 'Northwind');
WriteString('Description', 'Keiths Test DSN description');
WriteString('Driver', 'C:\WINNT\system32\SQLSRV32.dll');
WriteString('Server', 'myserver');
WriteString('LastUser', 'sa');
CloseKey;
end;

(* Open ODBC Data Sources key to list the new DSN in the ODBC Manager.
Specify the new value. Close the key. *)

with Reg do
begin
RootKey := HKEY_LOCAL_MACHINE;
OpenKey('SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources', false); // do not
allow create in this case since it should already exist?
WriteString('Keiths Test DSN', 'SQL Server');
CloseKey;
end;

finally
Reg.Free;
end;

end;


.


Quantcast