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. 

相关阅读 >>

Delphi 线程教学第一节:初识多线程

Delphi 静态/动态调用dl

Delphi sql语句查询最新的各个台位的最后一个检测值

Delphi图像数据压缩解压缩实例

Delphi 提取标签之间的字符串(重复标签)

Delphi windows 编程[2] - 学习窗体生成的过程二

Delphi 删除只读文件

Delphi 如何让scrollbox的内容与滚动条一起实时滚动

Delphi - 利用dll编程控制摄像头实现拍照、录制视频

最简单的Delphi驱动结束进程

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...