I want to create a database in SQL Server Management Studio through the program code, where I "prescribe" the command to create a new database:

CREATE DATABASE [{0}] CONTAINMENT = NONE ON PRIMARY ( NAME = N'{0}', FILENAME = N'C:\Temp\{0}.mdf' , SIZE = 5120KB , FILEGROWTH = 1024KB ) LOG ON ( NAME = N'{0}_log', FILENAME = N'C:\Temp\{0}_log.ldf' , SIZE = 13312KB , FILEGROWTH = 10%) GO ALTER DATABASE [{0}] SET COMPATIBILITY_LEVEL = 110 GO ALTER DATABASE [{0}] SET ANSI_NULL_DEFAULT OFF GO ALTER DATABASE [{0}] SET ANSI_NULLS OFF GO ALTER DATABASE [{0}] SET ANSI_PADDING OFF GO USE [{0}] GO IF NOT EXISTS (SELECT name FROM sys.filegroups WHERE is_default=1 AND name = N'PRIMARY') ALTER DATABASE [{0}] MODIFY FILEGROUP [PRIMARY] DEFAULT GO 

Is it possible in the below variable, where the server to which I want to connect is defined, do not specify the name of the database (as it practically does not exist yet) and create a new database or is it done differently?

  String sqlConnectionString = "Server = AMASNMSSQL01; Database = Test_database; Trusted_Connection = True;"; 

1 answer 1

No, it is impossible - but you can connect to a database that obviously exists. For example, master .