Creates database on SQL Server. Used often before DBUp migrations.
Library allow us to create database from code. Database object exposes three methods:
- Create – it creates database. If database exists throws exception
- CreateSilent – it creates database, but before creation it checks if database exists. When true do nothing.
- Exists – checks if database exists
During creation of database connection string cannot contain database name so library removes it from the connection string if provided. From connection string:
"Server=.\\sql2019;Database=PTMeetings;Integrated Security=True"
Library will make and use
"Server=.\\sql2019;Integrated Security=True"
Database object implement IDatabase interface, so you can inject it or use it in tests if required.
Database database = new Database(name, "Server=.\\SQL2019;Trusted_Connection=True;");
database.Create();