September 2003
Intermediate to advanced
624 pages
14h 27m
English
You want to connect to an Oracle database.
You can connect to an Oracle database using either the Oracle .NET data provider or the OLE DB .NET data provider.
The sample code contains two event handlers:
Button.Click Creates and opens a connection to an Oracle database using the Oracle
.NET data provider. Information about the database is displayed from
the properties of the OracleConnection object.
Button.ClickCreates and opens a connection to an Oracle database using the OLE DB
.NET data provider. Information about the database is displayed from
the properties of the OleDbConnection object.
The C# code is shown in Example 1-7.
Example 1-7. File: ConnectOracleForm.cs
// Namespaces, variables, and constants using System; using System.Configuration; using System.Data.OleDb; using System.Data.OracleClient; // . . . private void oracleProviderButton_Click(object sender, System.EventArgs e) { // Connect to Oracle using Microsoft Oracle .NET data provider. OracleConnection conn = new OracleConnection( ConfigurationSettings.AppSettings["Oracle_Scott_ConnectString"]); resultTextBox.Text = "Connection with ORACLE Provider" + Environment.NewLine; try { conn.Open( ); resultTextBox.Text += "ConnectionState = " + conn.State + Environment.NewLine + "DataSource = " + conn.DataSource + Environment.NewLine + "ServerVersion = " + conn.ServerVersion + Environment.NewLine; } catch(OracleException ex) { resultTextBox.Text += "ERROR: " + ...Read now
Unlock full access