This documentation is archived and is not being maintained.

OdbcConnection.DataSource Property

Note: This namespace, class, or member is supported only in version 1.1 of the .NET Framework.

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

[Visual Basic]
Public ReadOnly Property DataSource As String
[C#]
public string DataSource {get;}
[C++]
public: __property String* get_DataSource();
[JScript]
public function get DataSource() : String;

Property Value

The server name or file name of the data source. The default value is an empty string ("") until the connection is opened.

Remarks

Retrieving the DataSource property is equivalent to calling the ODBC function SQLGetInfo with the InfoType parameter set to SQL_SERVER_NAME.

Example

[Visual Basic, C#, C++] The following example creates an OdbcConnection and displays the backend data source name.

[Visual Basic] 
Public Sub CreateOdbcConnection()
    Dim myConnString As String = _
       "DRIVER={SQL Server};SERVER=MyServer;Trusted_connection=yes;DATABASE=northwind;"
    Dim myConnection As New OdbcConnection(myConnString)
    myConnection.Open()
    MessageBox.Show("ServerVersion: " + myConnection.ServerVersion _
       + ControlChars.NewLine + "DataSource: " + myConnection.DataSource)
    myConnection.Close()
End Sub

[C#] 
public void CreateOdbcConnection() 
{
   string myConnString = "DRIVER={SQL Server};SERVER=MyServer;Trusted_connection=yes;DATABASE=northwind;";
   OdbcConnection myConnection = new OdbcConnection(myConnString);
   myConnection.Open();
   MessageBox.Show("ServerVersion: " + myConnection.ServerVersion
      + "\nDataSource: " + myConnection.DataSource);
   myConnection.Close();
}

[C++] 
public:
    void CreateOdbcConnection()
    {
        String* myConnString = S"DRIVER= {SQL Server};SERVER=MyServer;Trusted_connection=yes;DATABASE=northwind;";
        OdbcConnection* myConnection = new OdbcConnection(myConnString);
        myConnection->Open();
        MessageBox::Show(String::Concat(S"ServerVersion: ", myConnection->ServerVersion, S"\nDataSource: ", myConnection->DataSource));
        myConnection->Close();
    };

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

OdbcConnection Class | OdbcConnection Members | System.Data.Odbc Namespace | ConnectionTimeout | Database | ConnectionString

Show: