# Connection strings

The .NET SDK for SurrealDB supports the familiar concept of ConnectionString.

Connection Strings are an easy way to configure your application to connect to a SurrealDB instance.
They are stored in the <code>appsettings.json</code> file and can be used to configure the <code>SurrealDbClient</code>.

In general, it is known as a best practice to:

- set a development Connection String in <code>appsettings.Development.json</code>,
- store your production Connection String in a Secret environment variable, or even better in a Vault.

<table>
  <thead>
    <tr>
      <th scope="col">Keys</th>
      <th colspan="2" scope="col">
        Description
      </th>
      <th scope="col">Aliases</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td scope="row" data-label="Keys">
        <code>Endpoint</code>
        <label label="required" />
      </td>
      <td colspan="2" scope="row" data-label="Description">
        The database endpoint to connect to. <br />
        The disctinction between <code>Server</code> and <code>Client</code> can
        help you ensure you only call a distant database (server mode) or a
        local database (client mode).
      </td>
      <td scope="row" data-label="Aliases">
        <code>Server</code>
        <code>Client</code>
      </td>
    </tr>
    <tr>
      <td scope="row" data-label="Keys">
        <code>Namespace</code>
        <label label="optional" />
      </td>
      <td colspan="2" scope="row" data-label="Description">
        Switches to a specific namespace.
      </td>
      <td scope="row" data-label="Aliases">
        <code>NS</code>
      </td>
    </tr>
    <tr>
      <td scope="row" data-label="Keys">
        <code>Database</code>
        <label label="optional" />
      </td>
      <td colspan="2" scope="row" data-label="Description">
        Switches to a specific database.
      </td>
      <td scope="row" data-label="Aliases">
        <code>DB</code>
      </td>
    </tr>
    <tr>
      <td scope="row" data-label="Keys">
        <code>Username</code>
        <label label="optional" />
      </td>
      <td colspan="2" scope="row" data-label="Description">
        Username used to have root access.
      </td>
      <td scope="row" data-label="Aliases">
        <code>User</code>
      </td>
    </tr>
    <tr>
      <td scope="row" data-label="Keys">
        <code>Password</code>
        <label label="optional" />
      </td>
      <td colspan="2" scope="row" data-label="Description">
        Password used to have root access.
      </td>
      <td scope="row" data-label="Aliases">
        <code>Pass</code>
      </td>
    </tr>
    <tr>
      <td scope="row" data-label="Keys">
        <code>Token</code>
        <label label="optional" />
      </td>
      <td colspan="2" scope="row" data-label="Description">
        Token (JWT) used to have user access.
      </td>
      <td scope="row" data-label="Aliases"></td>
    </tr>
    <tr>
      <td scope="row" data-label="Keys">
        <code>AuthLevel</code>
        <label label="optional" />
      </td>
      <td colspan="2" scope="row" data-label="Description">
        Auth level when connecting to the SurrealDB instance. <br />
        Valid options are <code>Root</code>, <code>Namespace</code> or{" "}
        <code>Database</code>. <br />
        Defaults to <code>Root</code>.
      </td>
      <td scope="row" data-label="Aliases"></td>
    </tr>
  </tbody>
</table>

## Examples

Here is a couple of examples of Connection Strings:

```sh
Server=http://127.0.0.1:8000;Namespace=test;Database=test;Username=root;Password=secret
```

```sh
Endpoint=http://127.0.0.1:8000;NS=test;DB=test;User=root;Pass=secret
```

```sh
Server=ws://127.0.0.1:8000;AuthLevel=Namespace;NS=test;DB=test;User=root;Pass=secret
```

```sh
Client=mem://;Namespace=test;Database=test
```
