OleDbConnection.Database 属性

定义

获取当前数据库的名称或打开连接后要使用的数据库的名称。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

属性值

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.

实现

属性

示例

下面的示例创建 OleDbConnection 并显示其某些只读属性。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

注解

Database属性会动态更新。The Database property updates dynamically. 如果使用 SQL 语句或方法更改当前数据库 ChangeDatabase ,将发送一条信息性消息,并自动更新属性。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.

适用于

另请参阅