Operations: How to Add a Connection String
-
You can add a connection string by using the PutConnectionStringOperation method.
-
This article demonstrates how to connect to an external database.
In this page:
PutConnectionStringOperation
public PutConnectionStringOperation(T connectionString)
Parameters | Connection String Type | Description |
---|---|---|
connectionString | Raven |
Connection string to create: RavenConnectionString |
connectionString | Sql |
Connection string to create: SqlConnectionString |
ConnectionString
public class ConnectionString
{
public string Name { get; set; } // name of connection string
}
Add a Raven Connection String
Secure servers
To connect secure RavenDB servers you need to
- Export the server certificate from the source server.
- Install it as a client certificate on the destination server.
PutConnectionStringOperation<RavenConnectionString> operation
= new PutConnectionStringOperation<RavenConnectionString>(
new RavenConnectionString
{
Name = "raven2",
Database = "Northwind2",
TopologyDiscoveryUrls = new[]
{
// Be sure to include the "s" in https for secure servers.
"https://rvn2:8080"
}
});
PutConnectionStringResult connectionStringResult
= store.Maintenance.Send(operation);
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; }
Add an 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);
SqlConnectionString
public class SqlConnectionString : ConnectionString { public string ConnectionString { get; set; } public string FactoryName { get; set; } public ConnectionStringType Type => ConnectionStringType.Sql; }