Skip to content
Create SQL database in .NET projects.
C#
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Images
ProductivityTools.CreateSQLServerDatabase.Tests
ProductivityTools.CreateSQLServerDatabase
.gitignore
.powershell
ProductivityTools.CreateSQLServerDatabase.sln
README.md

README.md

CreateSQLServerDatabase

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.

Usage example

Database database = new Database(name, "Server=.\\SQL2019;Trusted_Connection=True;");
database.Create();

Create database

You can’t perform that action at this time.