DbConnection.DataSource Property

Definition

When overridden in a derived class, gets the name of the database server to which to connect.

C#
public abstract string DataSource { get; }

Property Value

The name of the database server to which to connect. The default value is an empty string.

Remarks

If the connection to the database is closed, the DataSource returns whatever is contained in the ConnectionString for the DataSource keyword. If the connection is open and the ConnectionString data source keyword's value starts with "|datadirectory|", the property returns whatever is contained in the ConnectionString for the DataSource 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 Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 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, 2.1
UWP 10.0

See also