Page 1 of 1

Create new Oracle database by code (Win x64 platform)

Posted: Sun 17 Jan 2016 13:16
by ertank
Hi,

I am testing both Unidac and Oracle Express 11.2 at the same time. I can establish a *direct* connection to after installation default database "xe" and use it. Connection is planned to be direct always. I can create tables, insert records, etc. I also need to create new oracle databases by code.

I am very new to Oracle. Internet searches lead me to a graphical tool to create a database which is not my intention.

Is it possible to create a new oracle database using UniDAC components? An example Delphi code showing how to do that would be great.

Thanks & regards,
Ertan

Re: Create new Oracle database by code (Win x64 platform)

Posted: Mon 18 Jan 2016 10:44
by MaximG
The used Oracle Express version 11.2 doesn't allow to create additional instances of the database, except the default XE database. Such a capability is provided only in the commercial licenses of Oracle. Approaches of creating an Oracle database are described in details in the documentation:

http://docs.oracle.com/cd/E11882_01/ser ... m#ADMIN002

Using Oracle Express 11.2, you can only create users in the current database. You can use UniDAC to do this:

Code: Select all

program ConsoleAppUniDAC;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,
  Data.DB, DBAccess, Uni, UniProvider, OracleUniProvider;
var
  UniConnection: TUniConnection;
begin
  UniConnection := TUniConnection.Create(nil);
  try
    UniConnection.ProviderName := 'Oracle';
    UniConnection.Server := 'XE';
    // User with DBA rights
    UniConnection.UserName := 'SYS';
    UniConnection.Password := <password>;
    UniConnection.Connect;
    UniConnection.ExecSQL('CREATE USER MYUSER IDENTIFIED BY MYPASSWORD');
    UniConnection.ExecSQL('GRANT CREATE SESSION TO MYUSER');
    UniConnection.Disconnect;
  finally
    UniConnection.Free;
  end;
end.
This console application creates a user MYUSER with password MYPASSWORD in the current database and grants him the right to create sessions.