使用unidac 在linux 上無驅動直接訪問MS SQL SERVER


隨着delphi 10.2 開始了對Linux 的重新支持。devart 也迅速的發布了unidac 7.0,

最大的特性就是支持linux和MongoDB.

並有了其他更新:

In this release we added such significant features as:

  • The new UniDAC version includes a new MongoDB provider which allows you to work with a cross-platform document-oriented database MongoDB. Its main features are high performance, easy deployment and comprehensive support for the latest versions of the MongoDB server.
  • In DBF provider, we added support for the Direct mode. Using DBF data provider, you can work with a variety of database formats: dBaseIII-dBase10, dBase for Windows, HiPer-Six, FoxPro 2, Visual FoxPro.
  • Now, working with Oracle in the Direct mode becomes more appealing, we supported Oracle 12c authentication, Oracle Cloud (DbaaS), Oracle Encryption, Oracle Data Integrity. We also added support for the ANYDATA type.
  • What is more, for Interbase and Firebird, you have an opportunity to manage batch operations using a transaction and to obtain an active transaction number using DBMonitor.
  • In NexusDB data provider, we added support for using ConnectionString and the TFmtBCD fields.

更多的情況可以訪問官網www.devart.com  .此公司在數據庫存取方面的功力,已經逆天。

今天給大家說的是利用undiac 的直連數據庫功能,在Linux下不安裝任何驅動,訪問MS SQLSERVER 功能。

如果你沒有現成的sql server 數據庫,可以直接在微軟的網頁上下載sql server 2016 express 版,此版本為免費版本。

安裝后,啟動TCP/IP 支持,同時注意windows 防火牆的設置,確保網絡訪問正常。

在windows 上,使用客戶端程序,建立一個sql server 數據庫,同時建一個測試表。

輸入一些測試數據

OK, 准備結束。啟動delphi。

新建一個控制台工程。

再建一個datamodule

放上對應的控件

注意uniconnection 的屬性設置

 

 ok, 設置完畢

回到主程序。

program linuxdata;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,System.Classes,
  dmp in 'dmp.pas' {dmf: TDataModule};

var
  i:integer;
  s:string;
begin

  try
   dmf:=Tdmf.Create(nil);
   dmf.UniConnection1.Connected:=true;
   writeln('數據庫版本:'+dmf.UniConnection1.ServerVersionFull);
with dmf.cx do begin SQL.Clear; sql.Add('select * from TB_user'); open; for I := 0 to fields.Count-1 do begin write('|'); write( fields[i].FieldName); end; writeln('|'); while not eof do begin for I := 0 to fields.Count-1 do begin write('|'); write( fields[i].AsString) ; end; writeln('|'); next; end; end; writeln('打完收功!'); readln; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; end.

在windows 上運行無誤。

 

添加linux 平台編譯支持

編譯,運行程序

 

 

 結果出來了。與windows 下沒任何區別。

記住:我們沒有在linux 下安裝任何sql server 驅動。

用delphi 就這么自信!

另外,以上人名,純屬虛構,如有雷同,愛理不理。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM