how do i check if database exist or not with mydac
-
martinloanel
- Posts: 2
- Joined: Wed 24 Feb 2016 20:30
how do i check if database exist or not with mydac
in my application if there is database not exist application raise exception because data base not exist how do i check if data base exist ?
Re: how do i check if database exist or not with mydac
If you want to detect whether the database you are trying to connect to is created, you can use the following code:
You can also do this check by having connected to MySQL server (e.g., to an always existing system mysql database). Use the following code for this:
Code: Select all
MyConnection.Database := 'DBName';
try
MyConnection.Connect;
ShowMessage('DBName exists.');
except
on E : Exception do
if Pos('Unknown database', E.Message) <> 0 then
begin
ShowMessage('DBName not exists.');
end;
end;Code: Select all
procedure TForm.ButtonClick(Sender: TObject);
var
Databases: TStringList;
begin
MyConnection.Database := 'mysql';
Databases := TstringList.Create;
try
MyConnection.GetDatabaseNames(Databases);
if Databases.IndexOf('DBName') <> -1 then
ShowMessage('DBName exists.')
else
ShowMessage('DBName not exists.');
finally
Databases.Free;
end;
end;-
martinloanel
- Posts: 2
- Joined: Wed 24 Feb 2016 20:30
Re: how do i check if database exist or not with mydac
thank you very much
Re: how do i check if database exist or not with mydac
If you have any questions during using our products, please don't hesitate to contact us - and we will try to help you solve them.