Is it possible to create a new database?

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
gezas
Posts: 19
Joined: Thu 15 Apr 2010 01:24

Is it possible to create a new database?

Post by gezas » Mon 14 Jan 2019 22:51

Hi,
is it possible to create a new SQL Server database using SDAC?
How?
Cheers
Geza

Stellar
Devart Team
Posts: 496
Joined: Tue 03 Oct 2017 11:00

Re: Is it possible to create a new database?

Post by Stellar » Tue 15 Jan 2019 14:39

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;

Post Reply