Get Connection String Operation
-
Use
GetConnectionStringsOperation
to retrieve properties for a specific connection string
or for all connection strings defined in the databse. -
To learn how to create a new connection string, see Add Connection String Operation.
-
In this page:
Get connection string by name and type
The following example retrieves a RavenDB Connection String:
using (var store = new DocumentStore())
{
// Request to get a specific connection string, pass its name and type:
// ====================================================================
var getRavenConStrOp =
new GetConnectionStringsOperation("ravendb-connection-string-name", ConnectionStringType.Raven);
GetConnectionStringsResult connectionStrings = store.Maintenance.Send(getRavenConStrOp);
// Access results:
// ===============
Dictionary<string, RavenConnectionString> ravenConnectionStrings =
connectionStrings.RavenConnectionStrings;
var numberOfRavenConnectionStrings = ravenConnectionStrings.Count;
var ravenConStr = ravenConnectionStrings["ravendb-connection-string-name"];
var targetUrls = ravenConStr.TopologyDiscoveryUrls;
var targetDatabase = ravenConStr.Database;
}
Get all connnection strings
using (var store = new DocumentStore())
{
// Get all connection strings:
// ===========================
var getAllConStrOp = new GetConnectionStringsOperation();
GetConnectionStringsResult allConnectionStrings = store.Maintenance.Send(getAllConStrOp);
// Access results:
// ===============
// RavenDB
Dictionary<string, RavenConnectionString> ravenConnectionStrings =
allConnectionStrings.RavenConnectionStrings;
// SQL
Dictionary<string, SqlConnectionString> sqlConnectionStrings =
allConnectionStrings.SqlConnectionStrings;
// OLAP
Dictionary<string, OlapConnectionString> olapConnectionStrings =
allConnectionStrings.OlapConnectionStrings;
// Elasticsearch
Dictionary<string, ElasticSearchConnectionString> elasticsearchConnectionStrings =
allConnectionStrings.ElasticSearchConnectionStrings;
// Access the Queue ETL connection strings in a similar manner:
// ============================================================
Dictionary<string, QueueConnectionString> queueConnectionStrings =
allConnectionStrings.QueueConnectionStrings;
var kafkaConStr = queueConnectionStrings["kafka-connection-string-name"];
}
Syntax
public GetConnectionStringsOperation()
public GetConnectionStringsOperation(string connectionStringName, ConnectionStringType type)
Parameter | Type | Description |
---|---|---|
connectionStringName | string |
Connection string name |
type | ConnectionStringType |
Connection string type:Raven , Sql , Olap , ElasticSearch , or Queue |
public enum ConnectionStringType
{
Raven,
Sql,
Olap,
ElasticSearch,
Queue
}
Return value of store.Maintenance.Send(GetConnectionStringsOperation) |
|
---|---|
GetConnectionStringsResult |
Class with all connection strings are defined on the database |
public class GetConnectionStringsResult
{
public Dictionary<string, RavenConnectionString> RavenConnectionStrings { get; set; }
public Dictionary<string, SqlConnectionString> SqlConnectionStrings { get; set; }
public Dictionary<string, OlapConnectionString> OlapConnectionStrings { get; set; }
public Dictionary<string, ElasticSearchConnectionString> ElasticSearchConnectionStrings { get; set; }
public Dictionary<string, QueueConnectionString> QueueConnectionStrings { get; set; }
}
A detailed syntax for each connection string type is available in article Add connection string.