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 MySQL Connection String

In our ADO.NET provider for MySQL, a connection string looks like the following:

User Id=root;Password=root;Host=localhost;Database=Test

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.

 

Here is a code example of assigning a connection string.

[C#]
public void CreateMySqlConnection()
{
  string myConnString1 = 
     "User Id=root;Host=localhost;Database=Test;";
  MySqlConnection myConnection1 = new MySqlConnection(myConnString1);
  myConnection1.Open();
}
	
[Visual Basic]
Public Sub CreateMySqlConnection()
  Dim myConnString1 As String = _
      "User Id=root;Host=localhost;Database=Test;"
  Dim myConnection1 As New MySqlConnection(myConnString1)
  myConnection1.Open()
End Sub
	

You can also use the MySqlConnectionStringBuilder class to form your connection string in a more convenient way.

[C#]
public void CreateMySqlConnection()
{
	MySqlConnectionStringBuilder myCSB = new MySqlConnectionStringBuilder();
	myCSB.Port = 3307;
	myCSB.Host = "localhost";
	myCSB.UserId = "root";
	myCSB.Password = "mypassword";
	myCSB.Direct = true;
	myCSB.Compress = true;
	myCSB.Database = "demobase";
	myCSB.MaxPoolSize = 150;
	myCSB.ConnectionTimeout = 30;
	MySqlConnection myConnection = new MySqlConnection(myCSB.ConnectionString);
}
	
[Visual Basic]
Public Sub CreateMySqlConnection()
	Dim myCSB As MySqlConnectionStringBuilder = New MySqlConnectionStringBuilder
	myCSB.Port = 3307
	myCSB.Host = "localhost"
	myCSB.UserId = "root"
	myCSB.Password = "mypassword"
	myCSB.Direct = True
	myCSB.Compress = True
	myCSB.Database = "demobase"
	myCSB.MaxPoolSize = 150
	myCSB.ConnectionTimeout = 30
	Dim myConnection As MySqlConnection = New MySqlConnection(myCSB.ConnectionString)
End Sub
	

For a more complete reference on MySQL connection string parameters, please see the ConnectionString property description and MySqlConnectionStringBuilder properties in dotConnect for MySQL documentation.

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:

User Id=Scott;Password=tiger;Data Source=Ora

In the Direct mode, a dotConect for Oracle connection string will look like the following:

User Id=Scott;Password=tiger;Direct=true;Data Source=192.168.0.1;Port=1521;SID=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.
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 more information about the Direct mode in dotConnect for Oracle see Using Direct Mode.

Here is a code example of assigning a connection string.

[C#]
public void CreateOraConnection()
{
        string oracleConnectionString1 = "User ID=Scott; Password=tiger; Data Source=ORA"; 
        OracleConnection oracleConnection1 = new OracleConnection(oracleConnectionString1); 
        oracleConnection1.Open(); 
 
        string oracleConnectionString2 = 
                "User ID=Scott; Password=tiger; Direct = true; Host=ORA; Service Name=SID; Port=1521;"; 
        OracleConnection oracleConnection2 = new OracleConnection(oracleConnectionString2); 
        oracleConnection2.Open(); 
}
	
[Visual Basic]
Public Sub CreateOraConnection()
        Dim OracleConnectionString1 As String = "User ID=Scott; Password=tiger; Data Source=ORA"
        Dim OracleConnection1 As New OracleConnection(OracleConnectionString1)
        OracleConnection1.Open()

        Dim OracleConnectionString2 As String = _
                "User ID=Scott; Password=tiger; Direct = true; Host=ORA; Service Name=SID; Port=1521;"
        Dim OracleConnection2 As New OracleConnection(OracleConnectionString2)
        OracleConnection2.Open()
End Sub
	

You can also use the OracleConnectionStringBuilder class to form your connection string in a more convenient way.

[C#]
public void CreateOracleConnection()
{
	OracleConnectionStringBuilder oraCSB = new OracleConnectionStringBuilder();
	oraCSB.Direct = true;
	oraCSB.Server = "192.168.0.1";
	oraCSB.Port = 1521;
	oraCSB.Sid = "orcl";
	oraCSB.UserId = "scott";
	oraCSB.Password = "tiger";
	OracleConnection myConnection = new OracleConnection(oraCSB.ConnectionString);
	myConnection.Open();
}
	
[Visual Basic]
Public Sub CreateOracleConnection()
	Dim oraCSB As OracleConnectionStringBuilder = New OracleConnectionStringBuilder
	oraCSB.Direct = true
	oraCSB.Server = "192.168.0.1"
	oraCSB.Port = 1521
	oraCSB.Sid = "orcl"
	oraCSB.UserId = "scott"
	oraCSB.Password = "tiger"
	Dim myConnection As OracleConnection = New OracleConnection(oraCSB.ConnectionString)
	myConnection.Open()
End Sub
	

For a more complete reference on Oracle connection string parameters, please see the ConnectionString property description and OracleConnectionStringBuilder properties in dotConnect for Oracle documentation.

dotConnect for PostgreSQL Connection String

In our ADO.NET provider for PostgreSQL, a connection string looks like the following:

host=server;database=test;user id=postgres;

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".

 

Here is a code example of assigning a connection string.

[C#]
public void CreatePgSqlConnection()
{
  string myConnString1 = 
     "host=server;database=test;user id=postgres;";
  PgSqlConnection pgConnection1 = new PgSqlConnection(myConnString1);
  pgConnection1.Open();
}
	
[Visual Basic]
Public Sub CreatePgSqlConnection()
  Dim myConnString1 As String = _
      "host=server;database=test;user id=postgres;"
  Dim pgConnection1 As New PgSqlConnection(myConnString1)
  pgConnection1.Open()
End Sub

	

You can also use the PgSqlConnectionStringBuilder class to form your connection string in a more convenient way.

[C#]
public void CreatePgSqlConnection()
{
	PgSqlConnectionStringBuilder pgCSB = new PgSqlConnectionStringBuilder();
	pgCSB.Host = "192.168.0.1";
	pgCSB.Port = 5432;
	pgCSB.UserId = "postgres";
	pgCSB.Password = "postgres";
	pgCSB.MaxPoolSize = 150;
	pgCSB.ConnectionTimeout = 30;
	PgSqlConnection myConnection = new PgSqlConnection(pgCSB.ConnectionString);
}
	
[Visual Basic]
Public Sub CreatePgSqlConnection()
	Dim pgCSB As PgSqlConnectionStringBuilder = New PgSqlConnectionStringBuilder
	pgCSB.Host = "192.168.0.1"
	pgCSB.Port = 5432
	pgCSB.UserId = "postgres"
	pgCSB.Password = "postgres"
	pgCSB.MaxPoolSize = 150
	pgCSB.ConnectionTimeout = 30
	Dim myConnection As PgSqlConnection = New PgSqlConnection(pgCSB.ConnectionString)
End Sub
	

For a more complete reference on PostgreSQL connection string parameters, please see the ConnectionString property description and PgSqlConnectionStringBuilder properties in dotConnect for PostgreSQL documentation.

dotConnect for SQLite Connection String

In our ADO.NET provider for SQLite, a connection string looks like the following:

DataSource=mydatabase.db

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.

 

Here is a code example of assigning a connection string.

[C#]
public void CreateSQLiteConnection()
{
  string myConnString1 = 
     "DataSource=mydatabase.db;";
  SQLiteConnection sqConnection1 = new SQLiteConnection(myConnString1);
  sqConnection1.Open();
}
	
[Visual Basic]
Public Sub CreateSQLiteConnection()
  Dim myConnString1 As String = _
      "DataSource=mydatabase.db;"
  Dim sqConnection1 As New SQLiteConnection(myConnString1)
  sqConnection1.Open()
End Sub
	

You can also use the SQLiteConnectionStringBuilder class to form your connection string in a more convenient way.

[C#]
public void CreateSQLiteConnection()
{
	SQLiteConnectionStringBuilder connSB = new SQLiteConnectionStringBuilder();
	connSB.DataSource = @"D:\TestApplication\database.db";
	connSB.FailIfMissing = false;
	connSB.Locking = LockingMode.Exclusive;
	connSB.AutoVacuum = AutoVacuumMode.Full;
	connSB.ConnectionTimeout = 20;
	SQLiteConnection sqLiteConnection1 = new SQLiteConnection(connSB.ConnectionString);
}
	
[Visual Basic]
Public Sub CreateSQLiteConnection()
	Dim connSB As SQLiteConnectionStringBuilder
	connSB.DataSource = "D:\TestApplication\database.db"
	connSB.FailIfMissing = false
	connSB.Locking = LockingMode.Exclusive
	connSB.AutoVacuum = AutoVacuumMode.Full
	connSB.ConnectionTimeout = 20
	Dim sqLiteConnection1 As SQLiteConnection(connSB.ConnectionString)
End Sub
	

For a more complete reference on SQLite connection string parameters, please see the ConnectionString property description and SQLiteConnectionStringBuilder properties in dotConnect for SQLite 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.