tailieunhanh - ODP .NET Developer's Guide oracle database 10g development with visual studio 2005 phần 2

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 đú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 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 Public Class Form3 Private Sub btnConnect_Click ByVal sender As ByVal e As Handles specify provider s invariant name Dim ProviderName As String _ create factory instance for the provider Dim fctry As DbProviderFactory _ ProviderName create connection based on the factory Dim Connection As Connection specify connection string _ Data Source xe user id scott password tiger Try try connecting to oracle close the connection before exiting Succesfully connected 20 Chapter 2 Catch ex As Exception display error message if not connected Unable to connect. 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. . Dim ProviderName As String _ Dim fctry As DbProviderFactory _ .

TỪ KHÓA LIÊN QUAN