Solved

Epsylon's Points.

Posted on 2001-07-11
4
229 Views
Last Modified: 2010-04-06
Here you go mate.
0
Comment
Question by:MoonCalf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 13

Accepted Solution

by:
Epsylon earned 50 total points
ID: 6272673
Thanks, but I didn't solve the problem...?
0
 
LVL 1

Author Comment

by:MoonCalf
ID: 6272762
The code that you both gave me was good code, just not really 100% what I asked for.  A few bodges and it worked great.

Thanks for your help Eps
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6272772
Thank you too. Always glad to help   :o)
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6272800
Just for my reference and in case they fix the search engine   :o)

http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20148582

Create access ODBC DSN programmatically

(* NOTE: THIS EXAMPLE IS NOT COMPLETE !!! *)

(*
 This example shows one way to load the ODBC
 Administrator's DLL (ODBCCP32.DLL) to create
 an Access MDB file and ODBC DSN pointing at
 it.  Note that it assumes current directory
 for both the DLL and the MDB, but the DLL
 will be found if in the WinSys directory which
 is where it normally is anyway.

 Similar operation applies to most driver types,
 with some modifications. eg: Access requires
 the MDB file to exist so you can hook the DSN
 to it.

 Note also that the "CREATE_DB" call is an Access
 special (MS Jet Engine) and has other variants
 like COMPACT_DB and REPAIR_DB. For a full list
 see either the Jet Engine Programmers Guide or
 the MSDN and search for "CREATE_DB".

 This was originally written in MSVC6 and was
 ported to Delphi 5.

 Full documentation can be found in the MSDN
 at http://msdn.microsoft.com/.
*)

const
 ODBC_ADD_DSN        = 1;    (* Add data source *)
 ODBC_CONFIG_DSN     = 2;    (* Configure (edit) data source *)
 ODBC_REMOVE_DSN     = 3;    (* Remove data source *)
 ODBC_ADD_SYS_DSN    = 4;    (* add a system DSN *)
 ODBC_CONFIG_SYS_DSN = 5;    (* Configure a system DSN *)
 ODBC_REMOVE_SYS_DSN = 6;    (* remove a system DSN *)

type
 TSQLConfigDataSource = function( hwndParent: HWND;
                                  fRequest: WORD;
                                  lpszDriver: LPCSTR;
                                  lpszAttributes: LPCSTR ) : BOOL; stdcall;


procedure Form1.FormCreate(Sender: TObject);
var
 pFn: TSQLConfigDataSource;
 hLib: LongWord;
 strDriver: string;
 strHome: string;
 strAttr: string;
 strFile: string;
 fResult: BOOL;
 ModName: array[0..MAX_PATH] of Char;
 srInfo : TSearchRec;
 hRegLib: HMODULE;
begin
 Windows.GetModuleFileName( HInstance, ModName, SizeOf(ModName) );
 strHome := ModName;
 while ( strHome[length(strHome)] <> '\' ) do
   Delete( strHome, length(strHome), 1 );
 strFile := strHome + 'TestData.MDB';   (* Test Access Rights (Axes =
Access) *)
 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=TestDSN'+#0+
                        'DBQ=%s'+#0+
                        'Exclusive=1'+#0+
                        'Description=Test Data'+#0+#0,
                        [strFile] );
     fResult := pFn( 0, ODBC_ADD_SYS_DSN, @strDriver[1], @strAttr[1] );
     if( fResult = false ) then ShowMessage( 'Create DSN (Datasource)
failed!' );

     (* test/create MDB file associated with DSN *)
     if( FindFirst( strFile, 0, srInfo ) <> 0 ) then
     begin
       strDriver := 'Microsoft Access Driver (*.mdb)';
       strAttr := Format( 'DSN=TestDSN'+#0+
                          'DBQ=%s'+#0+
                          'Exclusive=1'+#0+
                          'Description=Test Data'+#0+
                          'CREATE_DB="%s"'#0+#0,
                          [strFile,strFile] );
       fResult := pFn( 0, ODBC_ADD_SYS_DSN, @strDriver[1], @strAttr[1] );
       if( fResult = false ) then ShowMessage( 'Create MDB (Database file)
failed!' );
     end;
     FindClose( srInfo );

     end;

   (* MASSIVE SNIP *)
   FreeLibrary( hLib );
 end
 else
 begin
   ShowMessage( 'Unable to load ODBCCP32.DLL' );
 end;
 StatusClockTimer.Enabled := true;
end;
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses
Course of the Month6 days, 21 hours left to enroll

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question