Page 1 of 1

Is it possible to create a new database?

Posted: Mon 14 Jan 2019 22:51
by gezas
Hi,
is it possible to create a new SQL Server database using SDAC?
How?
Cheers
Geza

Re: Is it possible to create a new database?

Posted: Tue 15 Jan 2019 14:39
by Stellar
SDAC doe not have a method for creating a database. You can try creating a database with the following SQL query:
CREATE DATABASE [NewDBName]

For example, to create a database with the name 'database_name', that does not exist on the server:

Code: Select all

const
  DBName: 'database_name';

...

MSConnection1.Database := 'master';
MSConnection1.Connect;
MSConnection1.ExecSQL(
  ' IF (DB_ID(N' + QuotedStr(DBName) + ') IS NULL) ' +
  ' BEGIN' +
  '   CREATE DATABASE [' + DBName + '] ' +
  ' END;');
MSConnection1.Disconnect;
//connect to [database_name]
MSConnection1.Database := DBName;
MSConnection1.Connect;