Solved

TIBDatabase Create/Open Database - D7

Posted on 2006-10-19
11
2,662 Views
Last Modified: 2012-08-13
Hi Experts,

my form contains the following components:
    OpenDialog1: TOpenDialog;
    IBDatabase1: TIBDatabase;
    IBTransaction1: TIBTransaction;
    Button1: TButton;

By pressing Button1 I'd like to create a new database.

procedure TForm1.Button1Click(Sender: TObject);
begin
   if OpenDialog1.Execute then
      IBDatabase1.DatabaseName := OpenDialog1.FileName;
   IBDatabase1.Params.Clear;
   IBDatabase1.Params.Add ('user_name=sysdba');
   IBDatabase1.Params.Add ('password=masterkey');
   IBDatabase1.SQLDialect := 3;
   IBDatabase1.CreateDatabase;
end;

Running the project I got the error message:

---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EIBInterBaseError with message 'Your user name and password are not defined. Ask your database administrator to set up an InterBase login'. Process stopped. Use Step or Run to continue.
---------------------------
OK   Help  
---------------------------

In principle the SYSDBA and masterkey are preset.
What is wrong? How can I open the created DB?

wbr Janos
0
Comment
Question by:kacor
  • 6
  • 5
11 Comments
 
LVL 3

Expert Comment

by:cobi100
Comment Utility
try it like this:

  if OpenDialog1.Execute then
      IBDatabase1.DatabaseName := OpenDialog1.FileName;
   IBDatabase1.Params.Clear;
   IBDatabase1.Params.Add ('USER ''SYSDBA''');
   IBDatabase1.Params.Add ('PASSWORD ''masterkey''');
   IBDatabase1.SQLDialect := 3;
   IBDatabase1.CreateDatabase;
0
 
LVL 10

Author Comment

by:kacor
Comment Utility
thanks, the half of points is yours! Could you answer my second question too: how to open a DB?
0
 
LVL 3

Expert Comment

by:cobi100
Comment Utility
didn't see that part of the question, try:

   IBDatabase1.Open;
0
 
LVL 10

Author Comment

by:kacor
Comment Utility
I used the same procedure:

procedure TForm1.Button2Click(Sender: TObject);
begin
   if OpenDialog1.Execute then
      IBDatabase1.DatabaseName := OpenDialog1.FileName;
   IBDatabase1.Params.Clear;
   IBDatabase1.Params.Add ('USER ''SYSDBA''');
   IBDatabase1.Params.Add ('PASSWORD ''masterkey''');
   IBDatabase1.SQLDialect := 3;
   IBDatabase1.LoginPrompt := False;
   IBDatabase1.Open;
end;

and the error message is:

---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EIBInterBaseError with message 'Your user name and password are not defined. Ask your database administrator to set up an InterBase login'. Process stopped. Use Step or Run to continue.
---------------------------
OK   Help  
---------------------------
0
 
LVL 3

Expert Comment

by:cobi100
Comment Utility
Actualy, just IBDatabase1.Open; will do

procedure TForm1.Button2Click(Sender: TObject);
begin
   IBDatabase1.Open;
end;

you have set all the parameters in this other method

procedure TForm1.Button1Click(Sender: TObject);
begin
  if OpenDialog1.Execute then
      IBDatabase1.DatabaseName := OpenDialog1.FileName;
   IBDatabase1.Params.Clear;
   IBDatabase1.Params.Add ('USER ''SYSDBA''');
   IBDatabase1.Params.Add ('PASSWORD ''masterkey''');
   IBDatabase1.SQLDialect := 3;
   IBDatabase1.CreateDatabase;
end;

if you want to check if the DB is active do something like:

  if IBDatabase1.Connected then
    ShowMessage('opened');
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 10

Author Comment

by:kacor
Comment Utility
This second works too. Thanks. Completely answered.

I outlined wrong my question. When I try to open an existing DB, my comment ID: 17777003 above is right unfortunately.
0
 
LVL 3

Expert Comment

by:cobi100
Comment Utility
oh I see, well you can remove the params, and access directly through the properties of the ibconnection, something like:

   IBDatabase1.Params.Clear; //to clear the params
   IBDatabase1.Username := 'SYSDBA';
   IBDatabase1.Password := 'masterkey';
   IBDatabase1.SQLDialect := 3;
   IBDatabase1.Open;
0
 
LVL 10

Author Comment

by:kacor
Comment Utility
Unfortunately this don't work. The debugger stops at lines

      IBDatabase1.Username := 'SYSDBA';
      IBDatabase1.Password := 'masterkey';

This is normal because they are parameters but the offered solution above for create database don't work too. I don't understand why accepts it for creating DB and for opening not.

Just a personal question: may I know your given name?

wbr Janos
0
 
LVL 3

Accepted Solution

by:
cobi100 earned 500 total points
Comment Utility
I see, well the thing is that the lines I gave you use the IB script syntax, if you were to open an IBManager you could enter a command to create a db, and the user and password must be specified like that. now for opening it;s a dirrerent story, it would be great if you could try it with your own code.... just for open:

   IBDatabase1.Params.Clear;
   IBDatabase1.Params.Add ('user_name=sysdba');
   IBDatabase1.Params.Add ('password=masterkey');

Cheers

BTW. I'm Alex
0
 
LVL 10

Author Comment

by:kacor
Comment Utility
Thanks Alex,

if you watch my original question I used this syntax to create a DB. I simply don't understand why have I to use different syntaxes for different commands. I have to to tell you I am only a "hobby" programmer - look at my member profile.

Again thank you for your support!

with best regards
Janos
0
 
LVL 3

Expert Comment

by:cobi100
Comment Utility
I'm glad it worked

-Alex
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Delphi 2010 Export to pdf 2 249
add combobox item based on numbers 9 97
code issue 8 84
How to renew a Delphi rad-studio licence? 5 33
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now