Get Server-Wide Connection Strings
-
Use
GetServerWideConnectionStringsOperationto retrieve a specific server-wide connection string,
or all server-wide connection strings defined at the cluster level. -
This operation reads server-wide connection strings from the cluster-level configuration.
To get connection strings stored in a single database's record, see Get per-database connection strings. -
Learn more about server-wide connection strings in Server-wide connection strings - Overview.
To create or update a server-wide connection string, see Add or update a server-wide connection string. -
In this article:
Get a server-wide connection string by name and type
The following example retrieves a server-wide Raven connection string:
- Sync
- Async
// Request a specific server-wide connection string, pass its name and type:
// =========================================================================
var getOp = new GetServerWideConnectionStringsOperation(
"ravendb-connection-string-name", ConnectionStringType.Raven);
GetServerWideConnectionStringsResult result = store.Maintenance.Server.Send(getOp);
// Access results:
// ===============
foreach (ServerWideConnectionString serverWideConStr in result.Results)
{
var name = serverWideConStr.Name;
var type = serverWideConStr.Type;
var excludedDatabases = serverWideConStr.ExcludedDatabases;
// The underlying connection string definition:
var ravenConStr = serverWideConStr.ConnectionString as RavenConnectionString;
}
// Request a specific server-wide connection string, pass its name and type:
// =========================================================================
var getOp = new GetServerWideConnectionStringsOperation(
"ravendb-connection-string-name", ConnectionStringType.Raven);
GetServerWideConnectionStringsResult result = await store.Maintenance.Server.SendAsync(getOp);
// Access results:
// ===============
foreach (ServerWideConnectionString serverWideConStr in result.Results)
{
var name = serverWideConStr.Name;
var type = serverWideConStr.Type;
var excludedDatabases = serverWideConStr.ExcludedDatabases;
// The underlying connection string definition:
var ravenConStr = serverWideConStr.ConnectionString as RavenConnectionString;
}
Get all server-wide connection strings
The following example retrieves all server-wide connection strings defined in the cluster:
- Sync
- Async
// Get all server-wide connection strings (all types):
// ====================================================
var getAllOp = new GetServerWideConnectionStringsOperation();
GetServerWideConnectionStringsResult result = store.Maintenance.Server.Send(getAllOp);
// Access results:
// ===============
List<ServerWideConnectionString> allConnectionStrings = result.Results;
foreach (ServerWideConnectionString serverWideConStr in allConnectionStrings)
{
var name = serverWideConStr.Name;
var type = serverWideConStr.Type;
var excludedDatabases = serverWideConStr.ExcludedDatabases;
// The underlying connection string definition:
var connectionString = serverWideConStr.ConnectionString;
}
// Get all server-wide connection strings (all types):
// ====================================================
var getAllOp = new GetServerWideConnectionStringsOperation();
GetServerWideConnectionStringsResult result = await store.Maintenance.Server.SendAsync(getAllOp);
// Access results:
// ===============
List<ServerWideConnectionString> allConnectionStrings = result.Results;
foreach (ServerWideConnectionString serverWideConStr in allConnectionStrings)
{
var name = serverWideConStr.Name;
var type = serverWideConStr.Type;
var excludedDatabases = serverWideConStr.ExcludedDatabases;
// The underlying connection string definition:
var connectionString = serverWideConStr.ConnectionString;
}
Syntax
public GetServerWideConnectionStringsOperation()
public GetServerWideConnectionStringsOperation(
string connectionStringName, ConnectionStringType type)
| Parameter | Type | Description |
|---|---|---|
| connectionStringName | string | Name of a specific server-wide connection string to retrieve. |
| type | ConnectionStringType | Connection string type:Raven, Sql, Olap, ElasticSearch, Queue, Snowflake, or Ai |
| Operation result | |
|---|---|
GetServerWideConnectionStringsResult | Contains Results - a list of the matching server-wide connection strings. |
public sealed class GetServerWideConnectionStringsResult
{
public List<ServerWideConnectionString> Results { get; set; }
}
Connection string type-specific fields and complete examples are documented in the task or feature articles listed under Connection string per type.