Muokkaa

Jaa


OleDbConnection.DataSource Property

Definition

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

public:
 virtual property System::String ^ DataSource { System::String ^ get(); };
public:
 property System::String ^ DataSource { System::String ^ get(); };
[System.ComponentModel.Browsable(true)]
public override string DataSource { get; }
[System.Data.DataSysDescription("OleDbConnection_DataSource")]
public string DataSource { get; }
[<System.ComponentModel.Browsable(true)>]
member this.DataSource : string
[<System.Data.DataSysDescription("OleDbConnection_DataSource")>]
member this.DataSource : string
Public Overrides ReadOnly Property DataSource As String
Public ReadOnly Property DataSource As String

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.

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.
    }
}
Public Sub OpenConnection(ByVal connectionString As String)

    Using connection As New OleDbConnection(connectionString)
        Try
            connection.Open()
            Console.WriteLine("Server Version: {0} DataSource: {1}", _
                connection.ServerVersion, connection.DataSource)
        Catch ex As Exception
            Console.WriteLine(ex.Message)
        End Try
        ' The connection is automatically closed when the
        ' code exits the Using block.
    End Using
End Sub

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

See also