Difference between revisions of "mssqlconn/pl"

From Free Pascal wiki
Jump to navigationJump to search
(→‎Documentation: tłumaczenie na j. polski)
(→‎Limitations and tips: tłumaczenie na j. polski)
Line 28: Line 28:
 
Oficjalna dokumentacja: [http://www.freepascal.org/docs-html/fcl/mssqlconn/index.html FPC MSSQLConn]
 
Oficjalna dokumentacja: [http://www.freepascal.org/docs-html/fcl/mssqlconn/index.html FPC MSSQLConn]
  
==Limitations and tips==
+
==Ograniczenia i wskazówki==
  
* Sybase port: the default port for Sybase ASE is 5000. As FreeTDS/mssqlconn uses 1433 by default, you may want to add :5000 to the hostname proprerty automatically or after feedback from the end user.
+
* Port Sybase: domyślny port TCP dla Sybase ASE to 5000. Ponieważ FreeTDS/mssqlconn domyślnie używa 1433, warto dodać :5000 do właściwości nazwy hosta automatycznie lub po otrzymaniu informacji zwrotnej od użytkownika końcowego.
  
As the documentation specifies:
+
Jak określa dokumentacja:
* you might need to tweak some parameters for BLOB support.  
+
* może być konieczne dostosowanie niektórych parametrów obsługi BLOB.
* MS SQL multiple resultsets (MARS) are not supported.
+
* MS SQL Wielokrotne zestawienia wyników MS SQL (MARS) nie są obsługiwane.
  
Change the drivername and/or position
+
Zmiana nazwy sterownika i/lub pozycji
* Put dblib as first unit in your .lpr and then call dblib.initialisedblib('/position/to/libsybdb.so')
+
* Umieść dblib jako pierwszy moduł w swoim .lpr, a następnie wywołaj dblib.initialisedblib('/ścieżka/do/libsybdb.so')
  
===Output parameters of stored procedures===
+
===Parametry wyjściowe procedur składowanych===
  
Also, '''TMSSQLConnection''' and '''TSybaseConnection''' do not support handling of return status and output parameters of stored procedures. For more informations see: http://www.freetds.org/faq.html#ms.output.parameters
+
Ponadto '''TMSSQLConnection''' i '''TSybaseConnection''' nie wspierają obsługi statusu zwrotu i parametrów wyjściowych procedur składowanych. Więcej informacji na stronie: http://www.freetds.org/faq.html#ms.output.parameters
As a workaround you can use something like:
+
Jako obejście możesz użyć czegoś takiego:
  
 
<syntaxhighlight lang=pascal>
 
<syntaxhighlight lang=pascal>
Line 53: Line 53:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Some more tips:
+
Kilka dodatkowych wskazówek:
* You might want to do an YourConnection.ExecuteDirect('SET ANSI_NULL_DFLT_ON ON'); if you want to automatically allow NULL values for columns when creating tables. See MS documentation: http://msdn.microsoft.com/en-us/library/ms174979.aspx
+
* Możesz chcieć zrobić YourConnection.ExecuteDirect('SET ANSI_NULL_DFLT_ON ON'); jeśli chcesz automatycznie zezwalać na wartości NULL dla kolumn podczas tworzenia tabel. Zobacz dokumentację MS: http://msdn.microsoft.com/en-us/library/ms174979.aspx
* You might want to similarly set SET ANSI_PADDING to ON to enable better compatibiity with sqldb text comparison functions. See MS documentation: http://msdn.microsoft.com/en-us/library/ms187403.aspx
+
* Możesz podobnie ustawić SET ANSI_PADDING to ON, aby umożliwić lepszą zgodność z funkcjami porównywania tekstu sqldb. Zobacz dokumentację MS: http://msdn.microsoft.com/en-us/library/ms174979.aspx
  
 
==Error messages==
 
==Error messages==

Revision as of 23:37, 12 November 2021

English (en) español (es) français (fr) polski (pl)

Moduł MSSQLConn
Databases portal

References:

Tutorials/practical articles:

Databases

Advantage - MySQL - MSSQL - Postgres - Interbase - Firebird - Oracle - ODBC - Paradox - SQLite - dBASE - MS Access - Zeos

MSSQLConn to moduł fcl-db zawierający kod konektora dla TMSSQLConnection (MS SQL Server) i TSybaseConnection (Sybase ASE).

Lazarus używa MSSQLConn do prezentowania konektora MS SQL i konektora Sybase ASE.

DBLib

MSSQLConn używa modułu niskiego poziomu dblib, który wymaga biblioteki FreeTDS (.dll/.dylib/.so) do połączenia z serwerem.

Instalacja

Jedyne, czego potrzebujesz, to biblioteka FreeTDS dll/dylib/so dla twojej platformy.

  • W systemie Linux pobierz pakiet freetds, który zawiera libsybdb.so (np. w Debianie/Raspbian jest to dostarczane przez pakiet libsybdb5) i powiązany jest z pakietem programistycznym za pomocą menedżera pakietów. Może być również konieczne dodanie dowiązania symbolicznego libsybdb.so do libsybdb.so.5
    • Ubuntu 20.04
      sudo apt install libsybdb5
      cd /usr/lib/x86_64-linux-gnu
      sudo ln -s libsybdb.so.5.1.0 libsybdb.so
  • W systemie Windows możesz pobrać najnowszą 32 lub 64-bitową wersję biblioteki FreeTDS dblib.dll tutaj: ftp://ftp.freepascal.org/fpc/contrib/windows/ lub http://downloads.freepascal.org/fpc/contrib/windows/

Zaawansowane użycie: przez modyfikację pliku FPC dblib.pas, SQLDB może używać „natywnej” biblioteki ntwdblib.dll zamiast domyślnej biblioteki FreeTDS dblib.dll (w tym przypadku FPC musi zostać przekompilowane).

Dokumentacja

Oficjalna dokumentacja: FPC MSSQLConn

Ograniczenia i wskazówki

  • Port Sybase: domyślny port TCP dla Sybase ASE to 5000. Ponieważ FreeTDS/mssqlconn domyślnie używa 1433, warto dodać :5000 do właściwości nazwy hosta automatycznie lub po otrzymaniu informacji zwrotnej od użytkownika końcowego.

Jak określa dokumentacja:

  • może być konieczne dostosowanie niektórych parametrów obsługi BLOB.
  • MS SQL Wielokrotne zestawienia wyników MS SQL (MARS) nie są obsługiwane.

Zmiana nazwy sterownika i/lub pozycji

  • Umieść dblib jako pierwszy moduł w swoim .lpr, a następnie wywołaj dblib.initialisedblib('/ścieżka/do/libsybdb.so')

Parametry wyjściowe procedur składowanych

Ponadto TMSSQLConnection i TSybaseConnection nie wspierają obsługi statusu zwrotu i parametrów wyjściowych procedur składowanych. Więcej informacji na stronie: http://www.freetds.org/faq.html#ms.output.parameters Jako obejście możesz użyć czegoś takiego:

with SQLQuery1 do begin
  SQL.Text := 'declare @param int; declare @ret int;' +
              'exec @ret=MyStoredProc 1, @param OUTPUT;' +
              'select @ret as return_status, @param as out_param';
  Open;
end;

Kilka dodatkowych wskazówek:

Error messages

Error 20009 : Unable to connect: Adaptive Server is unavailable or does not exist

  • Check if TCP/IP protocol is enabled on SQL Server side using "SQL Server Configuration Manager" - "SQL Server Network Configuration"
  • Check if TCP port 1433 is opened
  • If you connect to specific instance of SQL Server (this is also case of SQL Server Express), check if SQL Server Browser Service is running on server (service listens on UDP port 1434)

Error 20019 : Attempt to initiate a new Adaptive Server operation with results pending

Error 20047 : DBPROCESS is dead or not enabled

  • SQL Server periodically verifies (by default every 30 seconds) if idle TCP/IP connection is still intact by sending a keep alive packet to its peer. If the remote system is still reachable and functioning, a acknowledge packet is sent back. If not local TCP will reset connection.
  • Adjust SQL Server Configuration Manager -> SQL Server Network Configuration -> Protocols -> TCP/IP : "Keep Alive"

EINOutError/Can not load DB-Lib client library "dblib.dll". Check your installation

  • Make sure you have all required dlls installed (e.g. dblib.dll, libiconv2.dll)
  • Make sure you have all required C/C++ runtime libraries installed that dblib.dll depends on
  • Make sure the bitness (32 or 64 bit) of the dblib library and your compiled program match

Examples

Creating a database

The example below creates a database on an MS SQL Server. For this to work, the connection's parameter AutoCommit must be set to on. For normal subsequent connection you can switch it off again and use regular StartTransaction and Commit.

// Set up a form with a button called DBButton, 
// textbox called DatabaseNameEdit,
// '''MSSQLConnection''' called FConn
// ***make sure the Autocommit parameter is on for the create db part before connectiong:
//FConn.Params.Add('AutoCommit=true');
procedure TForm1.CreateDBButtonClick(Sender: TObject);
var
  CurrentDB: string;
begin
  if DatabaseNameEdit.Text = '' then
  begin
    showmessage('Empty database name. Please specify database name first.');
    exit;
  end;

  CurrentDB := FConn.DatabaseName;
  try
    // For FPC 2.6.1+
    FConn.ExecuteDirect('CREATE DATABASE ' + DatabaseNameEdit.Text);
    {
    // This works with FPC 2.7.1, not on 2.6.1
    FConn.CreateDB;
    }
  except
    on E: Exception do
    begin
      showmessage('Exception running CreateDB: ' + E.Message);
    end;
  end;
end;