Error assigning dynamic values to the Unidac Tuniconnection component

Asked

Viewed 1,243 times

2

Using Unidac components for Delphi XE5, I found an error when assigning dynamic values to the Tuniconnection component, responsible for connecting to the database.

Error message appears after Connected line := True;

dm = Datamodule where the component is.

try
  with dm.conServer do
  begin
    Server := 'localhost';
    Port := 5432;
    Username := 'postgres';
    Password := 'postgres';
    Database := 'newserver';
    Connected := True;
  end;
except
  on E: Exception do
    ShowMessage(E.ClassName + ' Erro : ' + E.Message);
end;

Código e Erro

Are any parameters missing? What would I be doing wrong?

2 answers

3


The example taken from the Unidac website shows how to make the connection:

var
  UniConnection1: TUniConnection;
...
UniConnection1.ProviderName := 'Oracle';
UniConnection1.Username := 'scott';
UniConnection1.Password := 'tiger';
UniConnection1.Server := 'ORA1020';
UniConnection1.SpecificOptions.Values['Schema'] := 'SCOTT';
UniConnection1.Open;

Each line of the Specificoptions property has the following format: =. >You can add options also using the method Add:

UniConnection1.SpecificOptions.Add('Schema=SCOTT');

Source: http://www.devart.com/unidac/docs/index.html?basics.htm

Just a hint. The use of with is dangerous as it does not guarantee that the properties you are setting are from the Object defined in with. If it does not find in with, it looks in Self automatically. In addition to hindering debug.

  • @Alexschmitt, always in order :D

  • Thanks for the information, they were very useful to me, but unfortunately not yet solved the problem, the error persists.

  • 1

    I will migrate to Firedac, I believe to be a good solution in addition to native. Thank you.

3

I was able to solve the problem using Firedac.

Used components of: Tfdguixwaitcursor, Tfdphyspgdriverlink and Tfdconnection.

Uses: System.Inifiles

procedure TfrmMain.FormCreate(Sender: TObject);
var
  appINI: TIniFile;
  Server, Username, Password, Database: String;
  Port: Integer;
begin
  direxe := IncludeTrailingPathDelimiter(ExtractFilePath(Application.ExeName));
  appINI := TIniFile.Create(direxe + 'config.ini');
  try
    Server := appINI.ReadString('Server', 'Server', '');
    Port := appINI.ReadInteger('Server', 'Port', 5432);
    Username := appINI.ReadString('Server', 'Username', '');
    Password := appINI.ReadString('Server', 'Password', '');
    Database := appINI.ReadString('Server', 'Database', '');
  finally
    appINI.Free;
    try
      dm.conServer.DriverName := 'PG';
      dm.conServer.Params.Add('Server=' + Server);
      dm.conServer.Params.Add('Port=' + IntToStr(Port));
      dm.conServer.Params.Add('Database=' + Database);
      dm.conServer.Params.Add('User_name=' + Username);
      dm.conServer.Params.Add('Password=' + Password);
      dm.conServer.Connected := True;
    except
    on E: Exception do
      ShowMessage(E.ClassName + ' Erro : ' + E.Message);
    end;
  end;
end;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.