> For the complete documentation index, see [llms.txt](https://docs.starcounter.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.starcounter.io/3.0.0-alpha-20190930/database-connection-string.md).

# Database connection string

**Note**: Starcounter 3.0.0 is currently in preview stage. This API might be changed in the future releases without backwards compatibility.

## Connection String options

| Name           | Type     | Required | Default Value       | Description                                                          |
| -------------- | -------- | -------- | ------------------- | -------------------------------------------------------------------- |
| `Database`     | `string` | True     | None                | Absolute or relative database directory path.                        |
| `OpenMode`     | `enum`   | False    | `CreateIfNotExists` | Specifies database creation strategy.                                |
| `StartMode`    | `enum`   | False    | `StartIfNotRunning` | Specifies database startup strategy.                                 |
| `StopMode`     | `enum`   | False    | `IfWeStarted`       | Specifies database shut down strategy.                               |
| `ContextCount` | `int`    | False    | 2 - 24              | Specifies number of database contexts allocated for this connection. |

### The `DatabaseOpenMode` enumeration values

* `Open` - Opens the database if it exist.
* `CreateIfNotExists` - Opens the database if it exist, and creates one if it doesn't.

### The `DatabaseStartMode` enumeration values

* `RequireStarted` - Expects database processes to be running, and won't attempt starting them.
* `StartIfNotRunning` - Connects if database processes are already running, and start them first if they are not.
* `StartExclusive` - Expects no database processes to be running, and start them if they are not. Refuse to connect if database processes are already running.

### The `DatabaseStopMode` enumeration values

* `IfWeStarted` - Stops database processes if they where started by the current application.
* `Never` - Leaves database processes running, even after the application shuts down and even if the application started them.

*Note: the `Never` option is not effective when the application process is forcibly killed with task manager or `Ctrl + C`. In this case operating system will kill corresponding Starcounter processes as well.*

### The `ContextCount` option

Starcounter has maximum of `31` database contexts available for allocation between multiple processes. By default, Starcounter application tries to allocate double as many contexts as CPU cores available, but minimum `2` and maximum `24`.

The ideal configuration is to have a database context per CPU core. Having more database contexts than CPU cores might increase performance in certain concurrent database access workloads. Having less database contexts than CPU cores might decrease performance of concurrent database access during high concurrent load.

Use `ContextCount` option to manually adjust database contexts allocation.

## Connection String sample

```
Database=./.database/Sample;OpenMode=CreateIfNotExists;StartMode=StartIfNotRunning;StopMode=IfWeStarted;ContextCount=10
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.starcounter.io/3.0.0-alpha-20190930/database-connection-string.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
