OdbcConnection Constructors

Definition

Initializes a new instance of the OdbcConnection class.

Overloads

OdbcConnection()

Initializes a new instance of the OdbcConnection class.

OdbcConnection(String)

Initializes a new instance of the OdbcConnection class with the specified connection string.

OdbcConnection()

Source:
OdbcConnection.cs
Source:
OdbcConnection.cs
Source:
OdbcConnection.cs

Initializes a new instance of the OdbcConnection class.

C#
public OdbcConnection();

Examples

The following example creates and opens an OdbcConnection.

C#
static private void CreateOdbcConnection()
{
    using (OdbcConnection connection = new OdbcConnection())
    {
        connection.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\Samples\\Northwind.mdb";
        connection.Open();
    }
}

Remarks

When a new instance of OdbcConnection is created, the write-only and read-only properties are set to the following initial values unless they are specifically set using their associated keywords in the ConnectionString property.

Properties Initial value
ConnectionString empty string ("")
ConnectionTimeout 15
Database empty string ("")

You can change the value for these properties only by using the ConnectionString property.

See also

Applies to

.NET 9 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

OdbcConnection(String)

Source:
OdbcConnection.cs
Source:
OdbcConnection.cs
Source:
OdbcConnection.cs

Initializes a new instance of the OdbcConnection class with the specified connection string.

C#
public OdbcConnection(string? connectionString);
C#
public OdbcConnection(string connectionString);

Parameters

connectionString
String

The connection used to open the data source.

Examples

The following example creates and opens an OdbcConnection.

C#
static private void CreateOdbcConnection()
{
    string connectionString = "Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\Samples\\Northwind.mdb";

    using (OdbcConnection connection = new OdbcConnection(connectionString))
    {
        connection.Open();
    }
}

Remarks

When a new instance of OdbcConnection is created, the write-only and read-only properties are set to the following initial values unless they are specifically set using their associated keywords in the ConnectionString property.

Properties Initial value
ConnectionString connectionString
ConnectionTimeout 15
Database empty string ("")

You can change the value for these properties only by using the ConnectionString property.

See also

Applies to

.NET 9 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)