Changing the Database for an Open Connection

[ Team LiB ] Recipe Changing the Database for an Open Connection Problem You want to change the database that a connection uses without recreating the connection. Solution Use the ChangeDatabase( ) method to change the database for a connection. | Team LiB Recipe Changing the Database for an Open Connection Problem You want to change the database that a connection uses without recreating the connection. Solution Use the ChangeDatabase method to change the database for a connection. The sample code creates a Connection to the Northwind database using the SQL Server .NET data provider. The connection is changed to use the pubs database. Finally the connection is closed. The Database property of the SqlConnection object is displayed throughout the sample for the different connection states. The C code is shown in Example 1-12. Example 1-12. File Namespaces variables and constants using System using using using using . . . StringBuilder result new StringBuilder Create the connection accessing Northwind database. SqlConnection conn new SqlConnection Sql_ConnectString Connection String Open the connection. Database Change the database to pubs. pubs Database Close the connection. Database Discussion The ChangeDatabase method is defined in the IDbConnection interface that represents a connection to a data source and is implemented by .NET data providers for relational databases including those for SQL Server Oracle and OLE DB. The ChangeDatabase method is used to change the current database for an open connection. It takes a single parameter that specifies the name of the database to use in place of the current database. The name of the database must be valid or .

Bấm vào đây để xem trước nội dung
TÀI LIỆU MỚI ĐĂNG
21    69    1    17-05-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.