how do icheck if database exist with mydac ?
Posted: Tue  04 Oct 2016 13:31
				
				how exactly i can return if database exits or not ? for example if its exist abort and don't do any thing .
			Discussion forums for open issues and questions concerning database tools, data access components and developer tools from Devart
https://forums.devart.com/
Code: Select all
  MyConnection.Database := 'DBName';
  try
    MyConnection.Connect;
  except
    on E: Exception do
      if Pos('Unknown database', E.Message) <> 0 then
        ShowMessage('Database "DBName" does not exist')
      else
        raise;
  end;Code: Select all
  MyQuery.SQL.Text := 'SELECT IF(EXISTS (SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = ''DBName''), ''Yes'', ''No'') ';
  MyQuery.Open;
  if MyQuery.Fields[0].AsString = 'No' then
    ShowMessage('Database "DBName" does not exist');Code: Select all
WHERE SCHEMA_NAME = '+variablename+'Code: Select all
WHERE SCHEMA_NAME = ' + QuotedStr(variablename) +'