Page 1 of 1

Console Application?

Posted: Wed 14 Oct 2009 15:58
by 99Percent
How do I write a console application using UniDAC? Is it possible?

I am trying something like this:

Code: Select all

unit UnitEmailReporter;

interface

procedure Connect;

implementation

uses Uni, UniProvider;

var
  UniConCajaConnection : TUniConnection;
  MSSQLUniProvider : TSQLServerUniProvider;

procedure Connect;
begin
  UniConCajaConnection:=TUniConnection.Create(nil);
  MSSSQLUniProvider : TSQLServerUniProvider.Create(nil);
  try
    with UniConCajaConnection do
    begin
      Server:='myserver.com';
      UserName:='sa';
      Password:='MyPassword';
      Database:='MyDatabase';
      ProviderName:='SQL Server';
      Connect;
    end;
    WriteLn('Connected!');
  finally
    UniConCajaConnection.Free;
    MSSSQLUniProvider.Free;
  end;
end;

end.
But I get this error: Undeclared Identifier: 'TSQLServerUniProvider'

Posted: Wed 14 Oct 2009 20:42
by tobias_cd
Add "SQLServerUniProvider" to your uses clause.

Posted: Wed 14 Oct 2009 22:16
by 99Percent
Thanks that solved the compile error.

But now I am getting a runtime exception:
"Class EOLEDBError with message 'OLE DB error occured. Code 800401F0h. CoInitialize has not been called.'"

Code: Select all

unit UnitEmailReporter;

interface

procedure Connect;

implementation

uses Uni, UniProvider, SQLServerUniProvider;

var
  UniConCajaConnection : TUniConnection;
  MSSQLUniProvider : TSQLServerUniProvider;

procedure Connect;
begin
  UniConCajaConnection:=TUniConnection.Create(nil);
  MSSQLUniProvider:=TSQLServerUniProvider.Create(nil);
  try
    with UniConCajaConnection do
    begin
      Server:='Myserver.com';
      UserName:='sa';
      Password:='MyPassword';
      Database:='MyDatabase';
      ProviderName:='SQL Server';
      Connect;
    end;
    WriteLn('Connected!');
  finally
    UniConCajaConnection.Free;
    MSSQLUniProvider.Free;
  end;
end;

end.

Posted: Thu 15 Oct 2009 06:14
by malinsky
Hi,

add uses "ActiveX" a initialization section with CoInitialize(nil);

PMal

Posted: Thu 15 Oct 2009 22:13
by 99Percent
That did it. Works wonderfully. Thanks.