Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Trước khi xây dựng chuỗi kết nối, hãy chắc chắn rằng bạn đã cấu hình và thử nghiệm tnsnames.ora đúng cách và có thể kết nối đến Oracle cơ sở dữ liệu. Nếu bạn đã có thể kết nối với máy chủ cơ sở dữ liệu Oracle, bạn không cần phải sửa đổi thêm. Nhưng bạn nên biết để mà chủ nhà bạn sẽ kết nối. Điều này là cần thiết, như là một khách hàng Oracle có thể | Connecting to Oracle Before building the connection strings make sure that you configured and tested tnsnames.ora properly and can connect to the Oracle database. If you can already connect to the Oracle database server you need not modify further. But you should know to which host you are going to connect. This is essential as an Oracle client could be configured to connect to more than one Oracle database server simultaneously. You can also configure and test these connections using a graphical wizard Net Configuration Assistant. Connecting Using .NET Data Provider Factory Classes The previous topic introduced .NET data provider factory classes and this section will use those classes to connect to an Oracle database. The following code demonstrates how to connect to an Oracle database using the .NET data provider factory classes Imports System.Data.Common Public Class Form3 Private Sub btnConnect_Click ByVal sender As System.Object ByVal e As System.EventArgs Handles btnConnect.Click specify provider s invariant name Dim ProviderName As String _ Oracle.DataAccess.Client create factory instance for the provider Dim fctry As DbProviderFactory _ DbProviderFactories.GetFactory ProviderName create connection based on the factory Dim Connection As Data.Common.DbConnection Connection fctry.CreateConnection specify connection string Connection.ConnectionString _ Data Source xe user id scott password tiger Try try connecting to oracle Connection.Open close the connection before exiting Connection.Close MessageBox.Show Succesfully connected 20 Chapter 2 Catch ex As Exception display error message if not connected MessageBox.Show Unable to connect. ex.Message End Try End Sub End Class From the preceding code we have the following statements that are used to create a factory instance for the .NET data provider selected in this case it is Oracle. DataAccess.Client . Dim ProviderName As String _ Oracle.DataAccess.Client Dim fctry As DbProviderFactory _ .