You are currently browsing legacy 4.1 version of documentation. Click here to switch to the newest 4.2 version.

We can help you with migration to the latest RavenDB

Contact Us Now
see on GitHub

Operations: How to Add a Connection String

You can add a connection string by using PutConnectionStringOperation.

Syntax

public PutConnectionStringOperation(T connectionString)

Parameters
connectionString T Connection string to create: RavenConnectionString or SqlConnectionString

RavenConnectionString

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

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

    public string FactoryName { get; set; }

    public ConnectionStringType Type => ConnectionStringType.Sql;

}

ConnectionString

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

Example - Add Raven Connection String

PutConnectionStringOperation<RavenConnectionString> operation
    = new PutConnectionStringOperation<RavenConnectionString>(
        new RavenConnectionString
{
    Name = "raven2",
    Database = "Northwind2",
    TopologyDiscoveryUrls = new[]
    {
        "http://rvn2:8080"
    }
});

PutConnectionStringResult connectionStringResult 
    = store.Maintenance.Send(operation);

Example - Add Sql Connection String

PutConnectionStringOperation<SqlConnectionString> operation 
    = new PutConnectionStringOperation<SqlConnectionString>(
        new SqlConnectionString
    {
        Name = "local_mysql",
        FactoryName = "MySql.Data.MySqlClient",
        ConnectionString = "host=127.0.0.1;user=root;database=Northwind"
    });

PutConnectionStringResult connectionStringResult 
    = store.Maintenance.Send(operation);