DB2 10.5 for Linux, UNIX, and Windows

DB2Connection.Database Property

Gets the name of the current database or the database to be used after a connection is opened.

Namespace:
IBM.Data.DB2
Assembly:
IBM.Data.DB2 (in IBM.Data.DB2.dll)

Syntax

[Visual Basic]
Public ReadOnly Property Database As String  Implements _
   IDbConnection.Database
[C#]
public string Database {get;}
[C++]
public: __property String* get_Database();
[JScript]
public function get Database() : String;
Implements:
IDbConnection.Database

Property value

The name of the current database. The default value is an empty string ("") until the connection is opened.

Remarks

Initially, the Database property is set in the connection string. The Database property can be updated by using the ChangeDatabase method. If you change the current database by using the ChangeDatabase method, an informational message is sent and then the property is updated.

Example

[Visual Basic, C#] The following example creates a DB2®Connection and changes the current database.

[Visual Basic]
Public Sub CreateDB2Connection()
     Dim myConnString As String = _
        "DATABASE=SAMPLE"
     Dim myConnection As New DB2Connection(myConnString)
     myConnection.Open()
     myConnection.ChangeDatabase("SAMPLE2")
     MessageBox.Show("Database: " + myConnection.Database.ToString())
     myConnection.Close()
 End Sub
[C#]
public void CreateDB2Connection()
 {
    string myConnString = "DATABASE=SAMPLE";
    DB2Connection myConnection = new DB2Connection(myConnString);
    myConnection.Open();
    myConnection.ChangeDatabase("SAMPLE2");
    MessageBox.Show("Database: " + myConnection.Database.ToString());
    myConnection.Close();
 }