Starcounter
HomeDownloadDocsCommunity
3.0.0-rc-20191212
3.0.0-rc-20191212
  • Introduction
  • Database classes
  • Transactions
  • Database connection string
  • Database creation options
  • Database access with Dependency Injection (DI)
  • Running Starcounter 3.0 applications under Docker
  • Publishing Starcounter 3.0 application
  • Database types
  • Database files
  • Database processes
  • Failover cluster
  • Error codes
  • star tool
  • SQL Queries
Powered by GitBook
On this page
  • Starcounter 3.0 release candidate 20191212 main changes
  • Dependency Injection (DI) and Starcounter
  • Requirements
  • Installation
  • Binaries
  • Application
  • Running with Visual Studio Code
  • Running with Visual Studio 2019
  • Extra information

Introduction

NextDatabase classes

Last updated 5 years ago

Starcounter 3.0.0 Release Candidate is available for general access.

Downloads:

  • archive with all required NuGet packages.

  • Starcounter command line star tool for Windows.

  • Starcounter command line star tool for Linux.

Please make sure to read our .

Starcounter 3.0 release candidate 20191212 main changes

  • setup using Windows Failover Cluster.

  • The star tool is a cross-platform console application with SQL REPL & database import/export features.

  • Starcounter apps can now be distributed as a regular .NET Core app in framework dependent and self contained modes. .

  • It's now possible to execute DML & DDL SQL statements using the star tool.

  • Starcounter namespace has been changed from Starcounter.Nova.App to Starcounter.Database.

Dependency Injection (DI) and Starcounter

  • Read more about Dependency Injection on the official Microsoft documentation page - .

  • Checkout controller with Starcounter database access using Dependency Injection (DI).

Requirements

  • Enough RAM to load database of targeted size.

  • It's recommended to have at least two CPU cores.

Installation

Note: This section assumes that you have required operating system and .NET Core 3.0.100 SDK installed.

Binaries

  • Create a folder for Starcounter binaries, for example Starcounter.3.0.0-rc-20191212.

  • Unzip downloaded archive into the folder.

Windows 10

On Windows Starcounter requires x64 version of Visual C++ to be installed. Download and install it from the Microsoft website:

Make sure to Unblock the archive after downloading prior to extracting it. See the screenshot below:

Ubuntu 18.04 & 19.10

Install prerequisites.

sudo apt-get install wget unzip
sudo apt-get install libaio1 libtinfo5
sudo add-apt-repository ppa:swi-prolog/stable
sudo apt-get update
sudo apt-get install swi-prolog-nox=7.\*

Download and unpack Starcounter binaries.

cd $HOME
mkdir Starcounter.3.0.0-rc-20191212
cd Starcounter.3.0.0-rc-20191212
wget https://starcounter.io/Starcounter/Starcounter.3.0.0-rc-20191212.zip
unzip Starcounter.3.0.0-rc-20191212.zip

Application

Create an application folder and initialize a .NET Core console application.

mkdir StarcounterConsoleSample
cd StarcounterConsoleSample

dotnet new console

All the following commands shall be executed from the StarcounterConsoleSample folder.

Setup NuGet to consume Starcounter packages feeds.

Create nuget.config file and add required package sources:

  • local, points to the Starcounter binaries folder.

  • Starcounter, points to https://www.myget.org/F/starcounter/api/v2.

NuGet tips:

End file should look similar to this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="local" value="[Starcounter.3.0.0-rc-20191212]" />
    <add key="Starcounter" value="https://www.myget.org/F/starcounter/api/v2" />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
</configuration>

Visual Studio Setup:

Visual Studio requires manual NuGet package sources configuration. For this go to the Tools → Options → NuGet Package Manager → Package Sources menu then add local and Starcounter feeds.

Note: Replace the [Starcounter.3.0.0-rc-20191212] value with the actual path to the folder with unzipped Starcounter binaries.

Add Starcounter.Database package reference

dotnet add package Starcounter.Database --version 3.0.0-*

Add minimal Starcounter database access

Replace content of the Program.cs file with the following:

using System;
using System.Linq;
using Starcounter.Database;
using Microsoft.Extensions.DependencyInjection;

namespace StarcounterConsoleSample
{
    [Database]
    public abstract class Person
    {
        public abstract string Name { get; set; }
    }

    public class Program
    {
        public static void Main()
        {
            string connectionString =
                "Database=./.database/StarcounterConsoleSample;"
                + "OpenMode=CreateIfNotExists;"
                + "StartMode=StartIfNotRunning;"
                + "StopMode=IfWeStarted";

            // Here we create a service collection that
            // we add the Starcounter services to.
            // When we call BuildServiceProvider(), we get an instance
            // that we can use to fetch service instances,
            // for example ITransactor, which we then can use to
            // to make database transactions.
            using var services = new ServiceCollection()
                .AddStarcounter(connectionString)
                .BuildServiceProvider();

            // Here we fetch our ITransactor instance from the service provider.
            var transactor = services.GetRequiredService<ITransactor>();

            // And here we use it to make a database transaction.
            var name = transactor.Transact(db =>
            {
                // Here inside the transaction,
                // we can use the IDatabaseContext instance
                // to interact with the Starcounter database.

                // We can query it using SQL
                // (which returns an IEnumerable<Person>
                // that we can use with LINQ).
                var p = db.Sql<Person>
                (
                    "SELECT p FROM Person p WHERE Name = ?",
                    "Jane"
                ).FirstOrDefault();

                if (p == null)
                {
                    // We can insert new rows in the database using Insert().
                    p = db.Insert<Person>();

                    // We write to the database row
                    // using standard C# property accessors.
                    p.Name = "Jane";
                }

                // Let's return the name as result of the transaction.
                return p.Name;
            });

            // And let's print it in the console
            Console.WriteLine(name);
        }
    }
}

For ASP.NET Core applications:

Update Startup.cs class with the following:

using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

namespace StarcounterMvcSample
{
    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            string connectionString =
                "Database=./.database/StarcounterMvcSample;"
                + "OpenMode=CreateIfNotExists;"
                + "StartMode=StartIfNotRunning;"
                + "StopMode=IfWeStarted";

            // This adds and configures Starcounter services to our application,
            // for example ITransactor,
            // that allows us to create database transactions.
            services.AddStarcounter(connectionString);
        }
    }
}

Note: Starcounter works with Kestrel Web Server only. IIS and IIS Express are not yet supported.

  • Open Visual Studio Code in the application folder (from command line: code ./).

  • Restore dependencies Visual Studio Code asks for.

  • Click Ctrl + F5 to start the application.

Everything should run out of the box.

  • Update Visual Studio 2019 to the latest version using Visual Studio Installer.

  • We checked version 16.3.0.

  • Open StarcounterConsoleSample.csproj from Visual Studio.

  • Click Ctrl + F5 to start the application.

Extra information

Before asking questions or reporting issues, please read these few lines, and maybe you will find an answer for your question.

or .

is also supported.

is also supported.

, SDK for development, runtime for production.

Note: Please let us know if you encounter any issues while working with Starcounter. We monitor our issue tracker and stand ready to assist.

Download into the folder.

.

Starcounter relies on a specific version of .

Default NuGet.config file can be created with command.

For more information on how to work with NuGet configurations, see by Microsoft.

.

.

Running with

Running with

Publishing application in a single file with is not yet supported.

Starcounter.3.0.0-rc-20191212.zip
star-3.0.0-rc-20191212.zip
star-3.0.0-rc-20191212.tar.gz
End User License Agreement for Starcounter Software
Starcounter failover
Read more
Dependency injection in ASP.NET Core
ASP.NET Core sample
Ubuntu 18.04.02 x64
Windows 10 Pro x64 Build 1903
Windows Subsystem for Linux (WSL)
Ubuntu 19.10 x64
.NET Core 3.0.100
GitHub: Starcounter/Home
Starcounter.3.0.0-rc-20191212.zip
The latest supported Visual C++ downloads
SWI-Prolog
dotnet new nugetconfig
this post
Read more about Starcounter database connection string
Read how to configure Starcounter database creation options
Visual Studio Code
Visual Studio 2019
dotnet publish /p:PublishSingleFile=true