0

I try to create a InterBase database on Delphi using TIBDatabase type.

ibdb:=TIBDatabase.Create(nil);
with ibdb do
  begin
    SQLDialect:=3;
    DatabaseName:=Self.name;
    Params.Clear;
    Params.Add('USER "SYSDBA"');
    Params.Add('PASSWORD "masterkey"');
    Params.Add('PAGE_SIZE 4096');
    LoginPrompt:=false;
    try
      CreateDatabase;
    except on E: Exception do
      ShowMessage('Can''t create database. '+E.Message);
    end;
  end;

Self.name is string like a 'localhost:C:\db.ib'. Code works without errors. Database file created. But IBConsole doesn't show this database on IB server. How can I check that database was added on server?

AN90
  • 67
  • 1
  • 10
  • Where is the database to be stored? You haven't passed a physical location. As far as I remember, creating a database is one of the few things that can't be done using components, but I may be wrong. – No'am Newman Jan 25 '16 at 08:07
  • `IBConsole doesn't show this database on IB server.` - what do you mean exactly? and why should it ? // Example - I just downloaded a .DOC file from WWW somewhere into my computer, but when I launch MS-Word it does not show that file outright. – Arioch 'The Jan 25 '16 at 08:08
  • Database file path is a local. I mean that in IBConsole doesn't have new database item. – AN90 Jan 25 '16 at 08:19
  • I don't think that's your real code: In "Params.Add('USERS "SYSDBA"');", it should be "USER". – MartynA Jan 25 '16 at 09:05

2 Answers2

1

The following works for me and avoids all the problems you've mentioned so far:

1 Start a new Delphi project

2 Drop a TIBDatabase onto the form

3 Add the following CreateDatabase procedure to the form

procedure TForm1.CreateDatabase;
begin
  IBDatabase1.SQLDialect:=3;
  IBDatabase1.DatabaseName := 'D:\aaad7\interbase\newdb.gdb';  //edit for
    //  your system & check that you have file-creation rights in the 
    //  database folder you want to use.

  IBDatabase1.Params.Clear;
  IBDatabase1.Params.Add('USER ''SYSDBA''');  // Note that this line
  //  contains 5 single-quotes and no double quotes

  //  Also note that the omission of the usual '=' between the 
  //  parameter name and value for the USER and PASSWORD is deliberate, 
  // because it's evidently required by the IB api

  IBDatabase1.Params.Add('PASSWORD ''masterkey''');  // Ditto

  IBDatabase1.LoginPrompt:=false;

  try
    IBDatabase1.CreateDatabase;
  except on E: Exception do
    ShowMessage('Can''t create database. '+E.Message);
  end;
end;

4 Add a TButton and set its OnClick event to call CreateDatabase.

5 Compile & run and click Button1.

Using Delphi 7 and Interbase XE7, this code successfully creates the newdb.gdb database and this database stays on disk after the Delphi application terminates. I can then open the database in IBConsole using the procedure described below. I cannot delete the databse file via the windows shell while IBConsole is running but I can after I close it.

Do you get the same result and, if you do, does that solve your problem and if not, why not?

Btw, I've written the CreateDatabase code to avoid the use of "with", because it usually creates more problems than it avoids and I loathe it, and to avoid the dynamic creation of the TIBDatabase component, because that serves no useful purpose.

Notes

  1. Once you have created a database in code as above, there is no need to "attach" it to IBConsole.Exe or to the Interbase server in order to be able to use it.
    You could set up an IBDatabase, IBTransaction and IBQuery to connect to it, and create tables in it by issuing "CREATE TABLE ..." SQL statements to it from the IBQuery.

  2. If you want the database to be listed in the IBConsole utility, you can either

a) Add it manually using the procedure in Previous Answer below or

b) Add it in code to the IBConsole configuration file, IBConsole.XML, which you will find in C:\users[your user name]\Appdata\Roaming\Embarcadero\Interbase, using a Delphi XML access library of your choice. If you add it using the manual procedure below, then close IBConsole.Exe so that the config file is updated on disk, you'll be able to examine the XML file and find the node for the database under the Server/Databases node. It will look something like

<key name="Newdb">
<value name="Accessed">A32BFE2475B3E440</value>
<value name="CaseSensitiveRole">0</value>
<value name="CharacterSet"/>
<value name="Created">7DB1327474B3E440</value>
<value name="DatabaseFiles">D:\aaad7\Interbase\NEWDB.GDB</value>
<value name="Encrypted">0</value>
<value name="EUA Enabled">0</value>
<value name="Password">096e6376786a78726d82</value>
<value name="Role"/>
<value name="Save DBAlias">1</value>
<value name="SEP"/>
<value name="Use DBAlias">0</value>
<value name="Username">SYSDBA</value>
<value name="UseSSL">0</value>
</key>

Previous answer

Try this:

  • In IBConsole, click the Local Server node and select its Databases node

  • Right-click the Databases node and select Add

  • In the Add database and Connect pop-up, click the button to the RHS of the File: field

  • From there, you should be able to navigate to and select your new database.

Tested with Interbase XE7 IBConsole.

If that doesn't work for you, exactly which step fails and how?

MartynA
  • 30,454
  • 4
  • 32
  • 73
  • Thank you for the answer! I need to create database and locate them on IB server in Delphi code. – AN90 Jan 25 '16 at 08:36
  • Well, you said "I mean that in IBConsole doesn't have new database item." - you were talking about IBConsole, nor Delphi. So, **exactly** do you mean by "locate them on the IB server in Delphi code"? Describe (in your q) exactly what steps you are doing and what happens. Btw, if you're trying to set the server and file name in the properties of a Delphi component, the filename is case sensitive. – MartynA Jan 25 '16 at 08:41
  • If database created on server she must be visible by tools that can work with this server. I debugs this code. He create file. I can't delete them while debugging is on because InterBase catch them. But when debugging is over server doesn't have this database and I can delete file. – AN90 Jan 25 '16 at 09:00
  • Well, if no other process has the db open, you should be able to delete it. – MartynA Jan 25 '16 at 09:06
  • But if adding was successful I will not delete file. – AN90 Jan 25 '16 at 09:11
  • Sorry. You don't seem to be making any effort to explain your problem clearly. I suggest you delete this question ad provide a Minimal, Complete and Verifiable Example (MCVE) – MartynA Jan 25 '16 at 09:40
  • I edit a question. I think that database not adds on server as result in Delphi code. But in process database seems adds to IB. – AN90 Jan 25 '16 at 10:44
  • Database file created and stays on disk after working application. I need to attach database to InterBase server. Maybe I need add some code. – AN90 Jan 26 '16 at 07:22
  • What do you mean by "attach database to Interbase server"? If you open the database in Delphi code, the server should automatically open it. – MartynA Jan 26 '16 at 07:39
  • I use "connected" property. Database file must be added directly on some database management system server. But it not doesn't happens. – AN90 Jan 26 '16 at 07:50
  • See the **Note** section I've added to my answer, which should answer how to make the new db appear in IBConsole.Exe using code. But see what I've said before that - there is **NO** need to "attach" the db to IBConsole in order to be able to access it from a Delphi app. IBConsole is a management utility, not the Interbase server, so it is irrelevant to using the db whether IBConsole "knows about it" or not. Anyway, I'm done - if this update doesn't answer your q, then I give up. – MartynA Jan 26 '16 at 16:19
  • @MartynA - I wonder if the OP wants to create a database on a remote IBServer and his code is creating the DB on his local machine ... – Hugh Jones Jan 26 '16 at 17:13
  • @HughJones: Maybe but his "Self.name is string like a 'localhost:C:\db.ib'. Code works without errors. Database file created. But IBConsole doesn't show this database on IB server." suggests a local db to me and that the OP is under the misapprehension that the db needs to appear in IBConsole in order to use it, which is plain wrong, of course. Anyway he'll be able to confirm/deny that he meat remote despite what he said. – MartynA Jan 26 '16 at 17:22
  • Thank you very much for the help! – AN90 Jan 26 '16 at 17:25
0

It seems I find the answer. Code creates database file and add database on InterBase server. It can be checked by isql utility. Strange that IBConsole and IBExpert don't show all databases on server in current moment but only created by the same tool as I understand.

AN90
  • 67
  • 1
  • 10