Menu
Simba Technologies
Simba Technologies

Simba MongoDB ODBC Driver with SQL Connector 2.2.3
Installation and Configuration Guide

Simba > Drivers > MongoDB > ODBC Installation Guide > Windows > Configuration > Using a Connection String

Using a Connection String

For some applications, you might need to use a connection string to connect to your data source. For detailed information about how to use a connection string in an ODBC application, refer to the documentation for the application that you are using.

The connection strings in the following sections are examples showing the minimum set of connection attributes that you must specify to successfully connect to the data source. Depending on the configuration of the data source and the type of connection you are working with, you might need to specify additional connection attributes. For detailed information about all the attributes that you can use in the connection string, see Driver Configuration Options.

DSN Connection String Example

The following is an example of a connection string for a connection that uses a DSN:

DSN=[DataSourceName]

[DataSourceName] is the DSN that you are using for the connection.

You can set additional configuration options by appending key-value pairs to the connection string. Configuration options that are passed in using a connection string take precedence over configuration options that are set in the DSN.

DSN-less Connection String Examples

Some applications provide support for connecting to a data source using a driver without a DSN. To connect to a data source without using a DSN, use a connection string instead.

Important:

When you connect to the data store using a DSN-less connection string, the driver does not encrypt your credentials.

The placeholders in the examples are defined as follows, in alphabetical order:

  • [MongoDBDatabase] is the database that you want to access.
  • [PortNumber] is the number of the TCP port that the MongoDB server uses to listen for client connections.
  • [ServerInfo] is the IP address or host name of the MongoDB server to which you are connecting.
  • [ServiceName] is the Kerberos service principal name of the MongoDB server.
  • [SetName] is the name of the replica set that you want to access.
  • [YourPassword] is the password corresponding to your user name.
  • [YourUserName] is the user name that you use to access the MongoDB server.

Connecting to a Standard MongoDB Server Without Authentication

The following is the format of a DSN-less connection string for a standard connection to a MongoDB server that does not require authentication:

Driver=Simba MongoDB ODBC Driver;Server=[ServerInfo];
Port=[PortNumber];Database=[MongoDBDatabase];

For example:

Driver=Simba MongoDB ODBC Driver;Server=192.168.222.160;
Port=27017;Database=TestData;

Connecting to a Standard MongoDB Server that Requires SCRAM-SHA-1 Authentication

The following is the format of a DSN-less connection string for a standard connection to a MongoDB server that requires SCRAM-SHA-1 authentication:

Driver=Simba MongoDB ODBC Driver;Server=[ServerInfo];
Port=[PortNumber];Database=[MongoDBDatabase];
authMechanism=SCRAM-SHA-1;UID=[YourUserName];
PWD=[YourPassword];

For example:

Driver=Simba MongoDB ODBC Driver;Server=192.168.222.160;
Port=27017;Database=TestData;authMechanism=SCRAM-SHA-1;
UID=simba;PWD=simba;

Connecting to a Standard MongoDB Server that Requires Kerberos Authentication

The following is the format of a DSN-less connection string for a standard connection to a MongoDB server that requires Kerberos authentication:

Driver=Simba MongoDB ODBC Driver;Server=[ServerInfo];
Port=[PortNumber];Database=[MongoDBDatabase];
authMechanism=GSSAPI;gssapiServiceName=[ServiceName];

For example:

Driver=Simba MongoDB ODBC Driver;Server=192.168.222.160;
Port=27017;Database=TestData;authMechanism=GSSAPI;
gssapiServiceName=mongodb;

Connecting to a Standard MongoDB Server that Requires LDAP Authentication

The following is the format of a DSN-less connection string for a standard connection to a MongoDB server that requires LDAP authentication:

Driver=Simba MongoDB ODBC Driver;Server=[ServerInfo];
Port=[PortNumber];Database=[MongoDBDatabase];
authMechanism=PLAIN;UID=[YourUserName];PWD=[YourPassword];

For example:

Driver=Simba MongoDB ODBC Driver;Server=192.168.222.160;
Port=27017;Database=TestData;authMechanism=PLAIN;
UID=simba;PWD=simba;

Connecting to a Replica Set Without Authentication

The following is the format of a DSN-less connection string for connecting to a replica set that does not require authentication:

Driver=Simba MongoDB ODBC Driver;Server=[ServerInfo];
Port=[PortNumber];Database=[MongoDBDatabase];
EnableReplicaSet=1;SecondaryServers=[Server1]:[PortNumber1], [Server2]:[PortNumber2];ReplicaSet=[SetName];

For example:

Driver=Simba MongoDB ODBC Driver;Server=192.168.222.160;
Port=27017;Database=TestData;EnableReplicaSet=1;
SecondaryServers=192.168.222.165:27017, 192.168.222.231:27017;ReplicaSet=TestSet;

Connecting to a Replica Set that Requires MongoDB User Name and Password Authentication

The following is the format of a DSN-less connection string for connecting to a replica set that requires MongoDB User Name and Password authentication:

Driver=Simba MongoDB ODBC Driver;Server=[ServerInfo];
Port=[PortNumber];Database=[MongoDBDatabase];
UID=[YourUserName];PWD=[YourPassword];EnableReplicaSet=1;
SecondaryServers=[Server1]:[PortNumber1], [Server2]:[PortNumber2];ReplicaSet=[SetName];

For example:

Driver=Simba MongoDB ODBC Driver;Server=192.168.222.160;
Port=27017;Database=TestData;UID=simba;PWD=simba;
EnableReplicaSet=1;SecondaryServers=192.168.222.165:27017, 192.168.222.231:27017;ReplicaSet=TestSet;

Connecting to a Replica Set that Requires Kerberos Authentication

The following is the format of a DSN-less connection string for connecting to a replica set that requires Kerberos authentication:

Driver=Simba MongoDB ODBC Driver;Server=[ServerInfo];
Port=[PortNumber];Database=[MongoDBDatabase];
authMechanism=GSSAPI;gssapiServiceName=[ServiceName];
EnableReplicaSet=1;SecondaryServers=[Server1]:[PortNumber1], [Server2]:[PortNumber2];ReplicaSet=[SetName];

For example:

Driver=Simba MongoDB ODBC Driver;Server=192.168.222.160;
Port=27017;Database=TestData;authMechanism=GSSAPI;
gssapiServiceName=ServiceName;EnableReplicaSet=1;
SecondaryServers=192.168.222.165:27017, 192.168.222.231:27017;ReplicaSet=TestSet;

Connecting to a Replica Set that Requires LDAP Authentication

The following is the format of a DSN-less connection string for connecting to a replica set that requires LDAP authentication:

Driver=Simba MongoDB ODBC Driver;Server=[ServerInfo];
Port=[PortNumber];Database=[MongoDBDatabase];
authMechanism=PLAIN;UID=[YourUserName];PWD=[YourPassword];
EnableReplicaSet=1;SecondaryServers=[Server1]:[PortNumber1], [Server2]:[PortNumber2];ReplicaSet=[SetName];

For example:

Driver=Simba MongoDB ODBC Driver;Server=192.168.222.160;
Port=27017;Database=TestData;authMechanism=PLAIN;
UID=simba;PWD=simba;EnableReplicaSet=1;
SecondaryServers=192.168.222.165:27017, 192.168.222.231:27017;ReplicaSet=TestSet;