delphi 动态库里查询是否联接数据库  
官方Delphi 学习QQ群: 682628230(三千人)\n
频道

delphi 动态库里查询是否联接数据库


library   ConnDBDll; 

{   Important   note   about   DLL   memory   management:   ShareMem   must   be   the 
    first   unit   in   your   library 's   USES   clause   AND   your   project 's   (select 
    Project-View   Source)   USES   clause   if   your   DLL   exports   any   procedures   or 
    functions   that   pass   strings   as   parameters   or   function   results.   This 
    applies   to   all   strings   passed   to   and   from   your   DLL--even   those   that 
    are   nested   in   records   and   classes.   ShareMem   is   the   interface   unit   to 
    the   BORLNDMM.DLL   shared   memory   manager,   which   must   be   deployed   along 
    with   your   DLL.   To   avoid   using   BORLNDMM.DLL,   pass   string   information 
    using   PChar   or   ShortString   parameters.   } 


uses 
    SysUtils, 
    Classes, 
    adodb, 
    Forms,ComObj; 

{$R   *.res}   

Function   GetSQLServerName:Variant;stdcall; 
var 
      SQLServer:   Variant;//uses   comobj; 
      ServerList:   Variant; 
begin 
        SQLServer   :=   CreateOleObject( 'SQLDMO.Application '); 
        ServerList:=   SQLServer.ListAvailableSQLServers; 
        Result:=ServerList;     
end; 

    Function   ConnFilesM(pw,user,db,computer:string):boolean;   stdcall; 
    var   connection:tadoconnection; 
        connstr:string; 
    begin 
            try 
        connection:=tadoconnection.Create(nil); 
        connstr:=   'Provider=SQLOLEDB.1;Password= '+pw+ ';Persist   Security   Info=True;User   ID= '+user+ ';Initial   Catalog= '+db+ ';Data   Source= '+computer; 
        connection.ConnectionString:=connstr; 
        connection.LoginPrompt:=false; 
        connection.Connected:=true; 
        result   :=   true; 
        with   Application   do           //uses   Forms 
            begin 
            NormalizeTopMosts; 
            MessageBox( '连接数据库成功! ',   '系统提示 ',0); 
            RestoreTopMosts; 
            end; 
        except 
        result   :=   false; 
        with   Application   do 
            begin 
            NormalizeTopMosts; 
            MessageBox( '连接数据库失败! ',   '系统提示 ',0); 
            RestoreTopMosts; 
            end; 
        end; 
    end;     
    exports   ConnFilesM,GetSQLServerName; 
begin 

end. 

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.38382911682129 seconds