Operations: How to Get Connection String

In this page:

GetConnectionStringsOperation

public GetConnectionStringsOperation()
public GetConnectionStringsOperation(string connectionStringName, ConnectionStringType type)
Parameters Data Type Description
connectionStringName string Connection string name
type ConnectionStringType Connection string type: Raven, Sql, or Olap
Type Return Value Return Value Type Description
SqlConnectionStrings Dictionary<string, SqlConnectionString> Dictionary that maps sql connection string name to definition  
RavenConnectionStrings Dictionary<string, RavenConnectionString> Dictionary that maps raven connection string name to definition  
OlapConnectionStrings Dictionary<string, OlapConnectionString> Dictionary that maps olap connection string name to definition  

Definitions

RavenConnectionString

A Raven connection string definition:

public class RavenConnectionString : ConnectionString
{
    public string Database { get; set; } // target database name
    public string[] TopologyDiscoveryUrls; // list of server urls

    public ConnectionStringType Type => ConnectionStringType.Raven;

}

SqlConnectionString

An Sql connection string definition:

public class SqlConnectionString : ConnectionString
{
    public string ConnectionString { get; set; }
    public string FactoryName { get; set; }

    public ConnectionStringType Type => ConnectionStringType.Sql;

}

OlapConnectionString

An Olap connection string definition:

public class OlapConnectionString : ConnectionString
{
    public string Name { get; set; }
    public LocalSettings LocalSettings { get; set; }
    public S3Settings S3Settings { get; set; }
    public AzureSettings AzureSettings { get; set; }
    public GlacierSettings GlacierSettings { get; set; }
    public GoogleCloudSettings GoogleCloudSettings { get; set; }
    public FtpSettings FtpSettings { get; set; }

    public ConnectionStringType Type => ConnectionStringType.Olap;
}

ConnectionString

A generic connection string definition:

public class ConnectionString
{
    public string Name { get; set; } // name of connection string        
}

Code Samples

Get all Connection Strings

using (var store = new DocumentStore())
{
    GetConnectionStringsOperation operation = new GetConnectionStringsOperation();
    GetConnectionStringsResult connectionStrings = store.Maintenance.Send(operation);
    Dictionary<string, SqlConnectionString> sqlConnectionStrings = connectionStrings.SqlConnectionStrings;
    Dictionary<string, RavenConnectionString> ravenConnectionStrings = connectionStrings.RavenConnectionStrings;
    Dictionary<string, OlapConnectionString> olapConnectionStrings = connectionStrings.OlapConnectionStrings;
}

Get Connection String By Name and Type

using (var store = new DocumentStore())
{
    GetConnectionStringsOperation operation =
        new GetConnectionStringsOperation("local_mysql", ConnectionStringType.Sql);
    GetConnectionStringsResult connectionStrings = store.Maintenance.Send(operation);
    Dictionary<string, SqlConnectionString> sqlConnectionStrings = connectionStrings.SqlConnectionStrings;
    SqlConnectionString mysqlConnectionString = sqlConnectionStrings["local_mysql"];
}