OleDbConnection.ChangeDatabase(String) Method
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.
Changes the current database for an open OleDbConnection.
public:
override void ChangeDatabase(System::String ^ value);
public:
virtual void ChangeDatabase(System::String ^ value);
public override void ChangeDatabase(string value);
public void ChangeDatabase(string value);
override this.ChangeDatabase : string -> unit
abstract member ChangeDatabase : string -> unit
override this.ChangeDatabase : string -> unit
Public Overrides Sub ChangeDatabase (value As String)
Public Sub ChangeDatabase (value As String)
- value
- String
The database name.
The database name is not valid.
The connection is not open.
Cannot change the database.
The following example creates an OleDbConnection and displays some of its read-only properties.
static void ChangeDatabaseConnection(string connectionString)
{
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
try
{
connection.Open();
Console.WriteLine("ServerVersion: {0} \nDatabase: {1}",
connection.ServerVersion, connection.Database);
connection.ChangeDatabase("Northwind");
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 ChangeDatabaseConnection(ByVal connectionString As String)
Using connection As New OleDbConnection(connectionString)
Try
connection.Open()
Console.WriteLine("Server Version: {0} Database: {1}", _
connection.ServerVersion, connection.Database)
connection.ChangeDatabase("Northwind")
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
The value supplied in the database
parameter must be a valid database name. The database
parameter cannot contain a null value, an empty string, or a string with only blank characters.
Product | Versions |
---|---|
.NET | 8 (package-provided), 9 (package-provided) |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided) |
.NET feedback
.NET is an open source project. Select a link to provide feedback: