Mssqlconn/pl

This is an old revision of Mssqlconn/pl, edited by Slawek at . The current revision is 144276.

/* Limitations and tips */ tłumaczenie na j. polski

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.

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

Jak określa dokumentacja:

Zmiana nazwy sterownika i/lub pozycji

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

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

Error 20047 : DBPROCESS is dead or not enabled

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

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;