"Paul Petroniu Marza" <pa...@acinta.dk> wrote in message
news:3ac8741b$1_1@dnews...
> Hello everybody,
>
> I am wondering if any of you ever succeeded to create a DSN
programatically
> from Delphi. If you did, can you help me with this?
>
> TIA,
> Paul
>
>
>"Paul Petroniu Marza" <pa...@acinta.dk> wrote in message
>news:3ac8741b$1_1@dnews...
>> Hello everybody,
>>
>> I am wondering if any of you ever succeeded to create a DSN programatically
>> from Delphi. If you did, can you help me with this?
I have not done it from Delphi, but I have done it from C++. You can see
an example of this in CodeCentral by looking at my two entries. The entry
with the lower ID number is the one which has the code to programmatically
create a DSN...
Jerry Bloomfield (TeamB)
--
http://www.teamb.com Jers...@wwa.com
Please do *NOT* send private e-mail without prior permission (my anti-spam
filters will probably just delete it anyway <g>)
function CreateDSNAccess(p_strDSNName, p_strFile, p_strDescr: string):
boolean;
var
pFn: TSQLConfigDataSource;
hLib: longword;
strDriver: string;
strAttr: string;
begin
Result := TRUE;
hLib := LoadLibrary('ODBCCP32'); // load from default path
if (hLib <> NULL) then
begin @pFn := GetProcAddress(hLib, 'SQLConfigDataSource');
if (@pFn <> nil) then
begin
// force (re-)create DSN
strDriver := 'Microsoft Access Driver (*.mdb)';
strAttr := Format('DSN=' + p_strDSNName + #0 +
'DBQ=%s' + #0 +
'Exclusive=1' + #0 +
'Description=' + p_strDescr + #0 + #0,
[p_strFile]);
// if you want to create this database, replace the line above with these:
// 'CREATE_DB="%s"'#0 + #0,
// [p_strFile, p_strFile]);
Result := pFn(0, ODBC_ADD_DSN, @strDriver[1], @strAttr[1]);
end;
FreeLibrary(hLib);
end
else
begin
Raise EClassNotFound.Create('Unable to load ODBCCP32.DLL');
end;
end;
"Jerry Bloomfield (TeamB)" <Jers...@wwa.com> wrote in message
news:h28ictkvlgtgmvg4a...@4ax.com...
unit ODBC;
interface
Uses Windows;
Const
ODBC_ADD_DSN=1;
ODBC_CONFIG_DSN=2;
ODBC_REMOVE_DSN=3;
ODBC_ADD_SYS_DSN=4;
ODBC_CONFIG_SYS_DSN=5;
ODBC_REMOVE_SYS_DSN=6;
ODBC_REMOVE_DEFAULT_DSN=7;
Function SQLConfigDataSource(HwndParent:HWND;FRequest:WORD;Driver:PChar;
Attributes:Pchar):boolean;Stdcall;
implementation
Function SQLConfigDataSource;external 'odbccp32.dll' name 'SQLConfigDataSource';
end.
Call it like this:
SqlConfigDataSource(Application.Handle,ODBC_CONFIG_SYS_DSN,Pchar(<Driver name as displayed
in ODBC>),Pchar(<Attributes as in ODBC Admin>));