MySqlConnection.Database Property

MySQL Connector/Net

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

Namespace: MySql.Data.MySqlClient
Assembly: MySql.Data (in MySql.Data.dll) Version: 6.9.9
Syntax
public override string Database { get; }
Public Overrides ReadOnly Property Database As String
	Get
public:
virtual property String^ Database {
	String^ get () override;
}
abstract Database : string with get
override Database : string with get

Return Value

Type: String
The name of the current database or the name of the database to be used after a connection is opened. The default value is an empty string.

Implements

IDbConnectionDatabase
Remarks

The Database property does not update dynamically. If you change the current database using a SQL statement, then this property may reflect the wrong value. If you change the current database using the ChangeDatabase(String) method, this property is updated to reflect the new database.

Examples
The following example creates a MySqlConnection and displays some of its read-only properties.
public void CreateMySqlConnection()
{
string myConnString =
"Persist Security Info=False;database=test;server=localhost;user id=joeuser;pwd=pass";
MySqlConnection myConnection = new MySqlConnection( myConnString );
myConnection.Open();
MessageBox.Show( "Server Version: " + myConnection.ServerVersion
+ "\nDatabase: " + myConnection.Database );
myConnection.ChangeDatabase( "test2" );
MessageBox.Show( "ServerVersion: " + myConnection.ServerVersion
+ "\nDatabase: " + myConnection.Database );
myConnection.Close();
}
Public Sub CreateMySqlConnection()
Dim myConnString As String = _
"Persist Security Info=False;database=test;server=localhost;user id=joeuser;pwd=pass"
Dim myConnection As New MySqlConnection( myConnString )
myConnection.Open()
MessageBox.Show( "Server Version: " + myConnection.ServerVersion _
+ ControlChars.NewLine + "Database: " + myConnection.Database )
myConnection.ChangeDatabase( "test2" )
MessageBox.Show( "ServerVersion: " + myConnection.ServerVersion _
+ ControlChars.NewLine + "Database: " + myConnection.Database )
myConnection.Close()
End Sub

No code example is currently available or this language may not be supported.

No code example is currently available or this language may not be supported.

See Also