ADO.NET Connection Strings Examples
This page will help you to know main connection string parameters in our ADO.NET providers for databases. You can also find C# and VB code examples of connecting to a database, that you can use in your ASP.NET, Windows, and other applications.
dotConnect for Oracle Connection String
dotConnect for Oracle supports two connection modes: OCI and Direct. In the OCI connection mode, dotConnect for Oracle uses Oracle Client software to connect to Oracle. In the Direct mode, dotConnect for Oracle connects directly and does not require Oracle Client.
In the OCI mode, a dotConect for Oracle connection string looks like the following:
Server=127.0.0.1;UserId=demo;Password=test
In the Direct mode, a dotConect for Oracle connection string will look like the following:
Direct=true;Server=127.0.0.1;UserId=demo;Password=test;Port=1521;ServiceName=orcl
The following table lists dotConnect for Oracle connection string parameters, specific to the Direct mode:
Parameter | Description |
---|---|
Direct | Determines whether to use the Direct mode. |
Data Source (or Host, or Server) | In the Direct mode it should contain the IP address or DNS name of an Oracle server or the server specification in the same format as in a tnsnames.ora file. In the OCI mode it should contain a TNS alias. The server specification in the same format as in a tnsnames.ora file can also be used. |
Port | The port number to connect to. This parameter is used only in the Direct mode. |
ServiceName | Determines the service name for the database instance. |
SID | System identifier (Global Database Name). This parameter is used only in the Direct mode. |
The following table lists other main dotConnect for Oracle connection string parameters:
Parameter | Description |
---|---|
Connect Mode | Allows opening a session with administrative privileges - as SYSDBA or SYSOPER. |
User Id | The Oracle login account. Leave blank if you want to use Integrated Security connections (OS authentication). |
Password | The password for the Oracle login account. Leave blank if you want to use Integrated Security connections (OS authentication). |
Unicode | Specifies whether dotConnect for Oracle uses UTF8 or UTF16 mode API calls. |
License Key | Specify your license key in this parameter. This is required only when using .NET Standard compatible assemblies. See Licensing .NET Standard (.NET Core) Projects for more information. |
For many examples and more complete reference on Oracle connection string parameters, please see the Oracle Connection String documentation.
dotConnect for MySQL Connection String
In our ADO.NET provider for MySQL, a connection string looks like the following:
Host=127.0.0.1;UserId=root;Password=mypassword;Database=test;Port=3306
The following table lists main dotConnect for MySQL connection string parameters:
Parameter | Description |
---|---|
Database | The name of the database. |
Host | The name or IP address of host of MySQL database to which to connect. |
User Id | The MySQL login account. |
Password | The password for the account. |
Port | The port of MySQL database to which to connect. The default value is 3306. |
Protocol | The type of the network protocol which will be used to access to MySQL server. |
License Key | Specify your license key in this parameter. This is required only when using .NET Standard compatible assemblies. See Licensing .NET Standard (.NET Core) Projects for more information. |
You also may be interested in SSH and SSL related parameters for establishing secure connections.
Parameter | Description |
---|---|
SSH Authentication Type | Client authentication method. See Devart.Common.SshAuthenticationType for additional information. |
SSH Cipher List | List of ciphers that client agrees to use. |
SSH Host | Name or ip address of an SSH server. |
SSH Password | User password for the SSH server. |
SSH Port | The port of MySQL database to which to connect. The default value is 3306. |
SSH Private Key | Location of the private key to use. |
SSH User | User id on the SSH server. |
SSL CA Cert | Location of authority certificate. |
SSL Cert | Location of client certificate. |
SSL Cipher List | List of ciphers that client agrees to use. |
SSL Key | Location of user's private key. |
For many examples and complete reference on MySQL connection string parameters, please see the MySQL Connection Strings documentation.
dotConnect for PostgreSQL Connection String
In our ADO.NET provider for PostgreSQL, a connection string looks like the following:
Host=127.0.0.1;UserId=postgres;Password=postgres;Database=postgres;Port=5432;Schema=public
The following table lists main dotConnect for PostgreSQL connection string parameters:
Parameter | Description |
---|---|
Database | The name of the database. |
Host | The name or IP address of host of PostgreSQL database to which to connect. |
User Id | The PostgreSQL login account. |
Password | The password for the account. |
Port | The port of PostgreSQL database to which to connect. The default value is 3306. |
Protocol | The Frontend/Backend Protocol version. Available values are 2 and 3. Set the parameter to 2 for the protocol version 2.0 or to 3 for protocol version 3.0. Can be applied only for PostgreSQL server versions 7.4 or higher, for earlier versions of PostgreSQL this parameter must be explicitly set to 2. To execute several statements in the same query set procol to 2 version. The default value is 3. |
Schema | The PostgreSQL schema to use. |
License Key | Specify your license key in this parameter. This is required only when using .NET Standard compatible assemblies. See Licensing .NET Standard (.NET Core) Projects for more information. |
You also may be interested in SSL-related parameters for establishing secure connections:
Parameter | Description |
---|---|
SSL CA Cert | Location of authority certificate. |
SSL Cert | Location of client certificate. |
SSL Cipher List | List of ciphers that client agrees to use. |
SSL Key | Location of user's private key. |
Ssl Mode | SSL connection priority. May be Disable, Allow, Prefer, and Require. The default value is Disable, which means that only an unencrypted SSL connection will be attempted. |
SSL TLS Protocol | Specifies the maximal TLS version to report to the server when establishing a connection. Supported values are "1.0", "1.1", and "1.2". The default value is "1.1". |
For many examples and more complete reference on PostgreSQL connection string parameters, please see the PostgreSQL Connection Strings documentation.
dotConnect for SQLite Connection String
In our ADO.NET provider for SQLite, a connection string looks like the following:
DataSource=database.db;FailIfMissing=False
The following table lists main dotConnect for SQLite connection string parameters:
Parameter | Description |
---|---|
Data Source | The path and name or the database to which to connect. |
License Key | Specify your license key in this parameter. This is required only when using .NET Standard compatible assemblies. See Licensing .NET Standard (.NET Core) Projects for more information. |
For many examples and more complete reference on SQLite connection string parameters, please see the SQLite Connection String documentation.
dotConnect for DB2 Connection String
In our ADO.NET provider for DB2, a connection string looks like the following:
DataSource=mydatabase.db
The following table lists main dotConnect for DB2 connection string parameters:
Parameter | Description |
---|---|
Database | The name of the database. |
Data Source -or- Host -or- Server | The name or IP address of host of DB2 database to which to connect. |
User Id | The DB2 login account. |
Password | The password for the account. |
License Key | Specify your license key in this parameter. This is required only when using .NET Standard compatible assemblies. See Licensing .NET Standard (.NET Core) Projects for more information. |
Here is a code example of assigning a connection string.
[C#]public void CreateDB2Connection() { string myConnString1 = "user id=db2admin;server=db2;database=SAMPLE;"; DB2Connection db2Connection1 = new DB2Connection(myConnString1); db2Connection1.Open(); }[Visual Basic]
Public Sub CreateDB2Connection() Dim myConnString1 As String = _ "user id=db2admin;server=db2;database=SAMPLE;" Dim db2Connection1 As New DB2Connection(myConnString1) db2Connection1.Open() End Sub
You can also use the DB2ConnectionStringBuilder class to form your connection string in a more convenient way.
[C#]public void CreateDB2Connection() { DB2ConnectionStringBuilder myCSB = new DB2ConnectionStringBuilder(); myCSB.Server = "db2:50000"; myCSB.UserId = "db2admin"; myCSB.Password = "mypassword"; myCSB.Database = "SAMPLE"; DB2Connection myConnection = new DB2Connection(myCSB.ConnectionString); }[Visual Basic]
Public Sub CreateDB2Connection() Dim myCSB As DB2ConnectionStringBuilder = New DB2ConnectionStringBuilder myCSB.Server = "db2:50000" myCSB.UserId = "db2admin" myCSB.Password = "mypassword" myCSB.Database = "SAMPLE" Dim myConnection As DB2Connection = New DB2Connection(myCSB.ConnectionString) End Sub
For a more complete reference on DB2 connection string parameters, please see the ConnectionString property description and DB2ConnectionStringBuilder properties in dotConnect for DB2 documentation.