Contribute to Docs Contribute to Docs

SQL Server

Please remember that if you're going to use our provided packages for ASP.NET Core Identity you will also need need to include the SQL Server package for Identity. For more information, please refer to article about using Identity for Piranha.

Whether you're using SQL Express, SQL Server or SQL Azure it's the same setup. SQL Server is a high performance database intended for production usage that can handle very high workloads.

Installation

To use SQL Server you need to add the NuGet package for running Piranha with Entity Framework Core as well as the Microsoft package for SQL Server.

<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.4" />
<PackageReference Include="Piranha.Data.EF" Version="7.0.2" />

Registering The DbContext

After you've made sure you have the package reference you need you simply specify that you want to use SQL Server and the connection information you want for your database in your Startup.cs. It's good practice to specify your connection string in your appsettings.json so you can have different connection strings for different environments.

{
    "ConnectionStrings": {
        "mydb": "Data Source=;Initial Catalog=;User Id=;Password=;MultipleActiveResultSets=True"
    }
}

When you've setup your configuration string you can then access it from your ConfigureServices.

public class Startup
{
    public IConfiguration Configuration { get; private set; }

    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public void ConfigureServices(IServiceCollection services)
    {
        ...

        services.AddPiranhaEF(options =>
            options.UseSqlServer(Configuration.GetConnectionString("mydb"));

        ...
    }
}

That's it! You're now using SQL Server with Piranha.