Export (0) Print
Expand All

OleDbConnection.DataSource Property

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.

Example

[Visual Basic, C#, C++] The following example creates an OleDbConnection and displays some of its read-only properties.

[Visual Basic] 
Public Sub CreateOleDbConnection()
    Dim myConnString As String = _
       "Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=Northwind;Integrated Security=SSPI;"
    Dim myConnection As New OleDbConnection(myConnString)
    myConnection.Open()
    MessageBox.Show("ServerVersion: " + myConnection.ServerVersion _
       + ControlChars.NewLine + "DataSource: " + myConnection.DataSource)
    myConnection.Close()
End Sub

[C#] 
public void CreateOleDbConnection() 
{
   string myConnString = "Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=Northwind;Integrated Security=SSPI;";
   OleDbConnection myConnection = new OleDbConnection(myConnString);
   myConnection.Open();
   MessageBox.Show("ServerVersion: " + myConnection.ServerVersion
      + "\nDataSource: " + myConnection.DataSource);
   myConnection.Close();
}

[C++] 
public:
 void CreateOleDbConnection() 
 {
    String* myConnString = S"Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=Northwind;Integrated Security=SSPI;";
    OleDbConnection* myConnection = new OleDbConnection(myConnString);
    myConnection->Open();
    MessageBox::Show(String::Format( S"ServerVersion: {0}\nDataSource: {1}", myConnection->ServerVersion, 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

OleDbConnection Class | OleDbConnection Members | System.Data.OleDb Namespace | ConnectionTimeout | Database | ConnectionString

Show:
© 2014 Microsoft