Creating a Database

Consider several examples of creating a database for connecting to repositories based on different DBMS. To execute the examples, add links to the Db and Metabase system assemblies.

Example 1

Consider an example of database creation in a repository based on Oracle server.

Sub UserProc;
Var
    MB: IMetabase;
    CrInfo: IMetabaseObjectCreateInfo;
    DB: IDatabase;
    Package: ISecurityPackage;
    OracleSPLD: IPrimaryOracleSPLD;
    PswCreds: IPasswordCredentials;
Begin
    MB := MetabaseClass.Active;
    // Create a database
    CrInfo := MB.CreateCreateInfo;
    CrInfo.ClassID := MetabaseObjectClass.KE_CLASS_DATABASE;
    CrInfo.Id := "NewORCLDB";
    CrInfo.Name := "New database";
    CrInfo.Parent := MB.Root;
    DB := MB.CreateObject(CrInfo).Edit As IDatabase;
    // Determine DBMS connection settings
    DB.Authentication := AuthenticationMode.Password;
    DB.DriverId := "ORCL8";
    OracleSPLD := DB.LogonData As IPrimaryOracleSPLD;
    OracleSPLD.Server := "TestServer";
    OracleSPLD.Scheme := "TestRepository";
    // Credentials
    Package := New StandardSecurityPackage.Create;
    PswCreds := Package.CreateCredentials(AuthenticationMode.Password) As IPasswordCredentials;
    PswCreds.UserName := "User";
    PswCreds.Password := "Password";
    DB.LoginPrompt := False;
    DB.Credentials := PswCreds;
    // Save changes
    (DB As IMetabaseObject).Save;
End Sub UserProc;

After executing the example, a new database is created in repository root. This database will be set up to connection to the TestRepository repository. The repository is located on Oracle server named TestServer. Automatic connection with the following credentials will be used: user name - User; password - Password.

Example 2

Consider an example of creation a database in a repository created on Microsoft SQL Server 2012\2014\2016 server.

Sub UserProc;
Var
    MB: IMetabase;
    CrInfo: IMetabaseObjectCreateInfo;
    DB: IDatabase;
    Package: ISecurityPackage;
    MSSPLD: IPrimaryMsSqlSPLD;
    PswCreds: IPasswordCredentials;
Begin
    MB := MetabaseClass.Active;
    // Create a database
    CrInfo := MB.CreateCreateInfo;
    CrInfo.ClassID := MetabaseObjectClass.KE_CLASS_DATABASE;
    CrInfo.Id := "NewMSSQLDB";
    CrInfo.Name := "New database";
    CrInfo.Parent := MB.Root;
    DB := MB.CreateObject(CrInfo).Edit As IDatabase;
    // Determine DBMS connection settings
    DB.Authentication := AuthenticationMode.Password;
    DB.DriverId := "MSSQL2012";
    DB.Unicode := True;
    MSSPLD := DB.LogonData As IPrimaryMsSqlSPLD;
    MSSPLD.Server := "TestServer";
    MSSPLD.Database := "TestRepository";
    // Credentials
    Package := New StandardSecurityPackage.Create;
    PswCreds := Package.CreateCredentials(AuthenticationMode.Password) As IPasswordCredentials;
    PswCreds.UserName := "User";
    PswCreds.Password := "Password";
    DB.LoginPrompt := False;
    DB.Credentials := PswCreds;
    // Save changes
    (DB As IMetabaseObject).Save;
End Sub UserProc;

After executing the example, a new database is created in repository root. This database will be set up to connection to the TestRepository repository. The repository is located on Microsoft SQL Server server named TestServer. Automatic connection with the following credentials will be used: user name - User; password - Password.

See also:

Examples