我用得是DELPHI7+ADO+ODBC,數據庫是ACCESS,該怎樣打包呀?ODBC是文件DSN,打包后無法連接數據庫請指示,謝謝!

解决方案 »

  1.   

    function TForm1.ConfigAccessODBC(aDSN:string;aDBName:string):boolean;
    var
      reg: TRegistry;
      bData : array[ 0..0 ] of byte;
      DrvPath : string;
    begin
      reg:= TRegistry.Create;
      with reg do
      begin
        RootKey:=HKEY_LOCAL_MACHINE;
        if OpenKey('SOFTWARE\ODBC\ODBCINST.INI\Microsoft Access Driver (*.mdb)',false) then
        begin
          DrvPath:=ReadString('Driver');
        end
        else
        begin //´´½¨¼üֵʧ°Ü
          //ShowMessage('¹«¹²ÐÅÏ¢'+'£º'+chr(10)+chr(10)+'ÄúûÓÐÕýÈ·°²×°Çý¶¯³ÌÐòMicrosoft Access Driver (*.mdb)£¬ÇëÖØа²×°!','´íÎóÐÅÏ¢', mb_applmodal+mb_iconerror+mb_ok+mb_defbutton1);
          ConfigAccessOdbc:=false;
          exit;
        end;
        Reg.CloseKey;
        //ÕÒµ½Software\ODBC\ODBC.INI\ODBC Data Sources
        if OpenKey('Software\ODBC\ODBC.INI\ODBC Data Sources',True) then
        begin
          WriteString(aDSN, 'Microsoft Access Driver (*.mdb)' );
        end
        else
        begin //´´½¨¼üֵʧ°Ü
          //application.MessageBox('¹«¹²ÐÅÏ¢'+'£º'+chr(10)+chr(10)+'ÅäÖÃODBCÊý¾ÝԴʧ°Ü£¡','´íÎóÐÅÏ¢', mb_applmodal+mb_iconerror+mb_ok+mb_defbutton1);
          ConfigAccessOdbc:=false;
          exit;
        end;
        CloseKey;
       //ÕÒµ½»ò´´½¨Software\ODBC\ODBC.INI\msac_infodb,дÈëDSNÅäÖÃÐÅÏ¢
       if OpenKey('Software\ODBC\ODBC.INI\'+aDSN,True) then
       begin
         WriteString( 'DBQ', aDBName);//Êý¾Ý¿âĿ¼£¬Á¬½ÓÄúµÄÊý¾Ý¿â
         WriteString( 'Description','ϵͳÐÅÏ¢Êý¾Ý¿âÊý¾ÝÔ´' );//Êý¾ÝÔ´ÃèÊö
         //WriteString( 'Driver', 'C:\WINNT\System32\odbcjt32.dll' );
         WriteString( 'Driver', DrvPath );//Çý¶¯³ÌÐòDLLÎļþ
         WriteInteger( 'DriverId', 25 ); //Çý¶¯³ÌÐò±êʶ
         WriteString( 'FIL', 'Ms Access;' );//FilterÒÀ¾Ý
         WriteInteger( 'SafeTransaction', 0 );//Ö§³ÖµÄÊÂÎñ²Ù×÷ÊýÄ¿
         WriteString( 'UID', '' );//Óû§Ãû³Æ
         bData[0] := 0;
         WriteBinaryData( 'Exclusive', bData, 1 ); //·Ç¶ÀÕ¼·½Ê½
         WriteBinaryData( 'ReadOnly', bData, 1 ); //·ÇÖ»¶Á·½Ê½
       end
       else//´´½¨¼üֵʧ°Ü
       begin
         //application.MessageBox('¹«¹²ÐÅÏ¢'+'£º'+chr(10)+chr(10)+'ÅäÖÃODBCÊý¾ÝԴʧ°Ü£¡','´íÎóÐÅÏ¢', mb_applmodal+mb_iconerror+mb_ok+mb_defbutton1);
         ConfigAccessOdbc:=false;
         exit;
       end;
       CloseKey;
      //ÕÒµ½»ò´´½¨Software\ODBC\ODBC.INI\msac_infodb\Engines\Jet
      //дÈëDSNÊý¾Ý¿âÒýÇæÅäÖÃÐÅÏ¢
       if OpenKey('Software\ODBC\ODBC.INI\'+aDSN+'\Engines\Jet',True) then
       begin
         WriteString( 'ImplicitCommitSync', 'Yes' );
         WriteInteger( 'MaxBufferSize', 512 );//»º³åÇø´óС
         WriteInteger( 'PageTimeout', 10 );//Ò³³¬Ê±
         WriteInteger( 'Threads', 3 );//Ö§³ÖµÄÏß³ÌÊýÄ¿
         WriteString( 'UserCommitSync', 'Yes' );
       end
       else//´´½¨¼üֵʧ°Ü
       begin
         //application.MessageBox('¹«¹²ÐÅÏ¢'+'£º'+chr(10)+chr(10)+'ÅäÖÃODBCÊý¾ÝԴʧ°Ü£¡','´íÎóÐÅÏ¢', mb_applmodal+mb_iconerror+mb_ok+mb_defbutton1);
         ConfigAccessOdbc:=false;
         exit;
       end;
       CloseKey;
       ConfigAccessOdbc:=True;
       Free;
      end;
    end;不好意思中文都是乱码,这是自动配置ODBC的程序
      

  2.   

    請教大家:請問大家在在做數據庫程序時是怎麼做的?  是用ADO嗎?那麼是ADO連接ODBC 嗎還是怎麼做?謝謝???!!!