kacor
asked on
TIBDatabase Create/Open Database - D7
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
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
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
ASKER
thanks, the half of points is yours! Could you answer my second question too: how to open a DB?
didn't see that part of the question, try:
IBDatabase1.Open;
IBDatabase1.Open;
ASKER
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
-------------------------- -
procedure TForm1.Button2Click(Sender
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
--------------------------
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');
procedure TForm1.Button2Click(Sender
begin
IBDatabase1.Open;
end;
you have set all the parameters in this other method
procedure TForm1.Button1Click(Sender
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');
ASKER
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.
I outlined wrong my question. When I try to open an existing DB, my comment ID: 17777003 above is right unfortunately.
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;
IBDatabase1.Params.Clear; //to clear the params
IBDatabase1.Username := 'SYSDBA';
IBDatabase1.Password := 'masterkey';
IBDatabase1.SQLDialect := 3;
IBDatabase1.Open;
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
I'm glad it worked
-Alex
-Alex
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