OleDbConnection.DataSource Property

Definition

Gets the server name or file name of the data source.

C#
[System.ComponentModel.Browsable(true)]
public override string DataSource { get; }
C#
[System.Data.DataSysDescription("OleDbConnection_DataSource")]
public string DataSource { get; }

Property Value

The server name or file name of the data source. The default value is an empty string.

Attributes

Examples

The following example creates an OleDbConnection and displays some of its read-only properties.

C#
static void OpenConnection(string connectionString)
{
    using (OleDbConnection connection = new OleDbConnection(connectionString))
    {
        try
        {
            connection.Open();
            Console.WriteLine("ServerVersion: {0} \nDataSource: {1}",
                connection.ServerVersion, connection.DataSource);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        // The connection is automatically closed when the
        // code exits the using block.
    }
}

Remarks

If the connection to the database is closed, the DataSource property returns whatever is contained in ConnectionString for the data source keyword. If the connection is open and the ConnectionString data source keyword's value starts with "|datadirectory|", the property returns whatever is contained in ConnectionString for the data source keyword only. If the connection to the database is open, the property returns what the native provider returns for the DBPROP_INIT_DATASOURCE, and if that is empty, the native provider's DBPROP_DATASOURCENAME is returned.

Applies to

Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (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, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

See also