OleDbConnection.Database Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the name of the current database or the database to be used after a connection is opened.
public:
virtual property System::String ^ Database { System::String ^ get(); };
public:
property System::String ^ Database { System::String ^ get(); };
public override string Database { get; }
[System.Data.DataSysDescription("OleDbConnection_Database")]
public string Database { get; }
member this.Database : string
[<System.Data.DataSysDescription("OleDbConnection_Database")>]
member this.Database : string
Public Overrides ReadOnly Property Database As String
Public ReadOnly Property Database As String
Property Value
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
- 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} \nDatabase: {1}",
connection.ServerVersion, connection.Database);
}
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} Database: {1}", _
connection.ServerVersion, connection.Database)
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
The Database property updates dynamically. If you change the current database using a SQL statement or the ChangeDatabase method, an informational message is sent and the property is updated automatically.
Applies to
See also
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈