C # Use instantclient to connect to Oracle 10 GB
1. Download instantclient-odbc-win32-10.2.0.3.zip from the oracle.com.
2. decompress the package to the instantclient directory.
32.16double-hit odbc_install.exe
4. Control Panel-> Administrative Tools-> data source (ODBC)-> add data source-> select oracle in instantclient10_2
Data source name can be any name. We recommend that you use the same name as Sid.
Description
The TNS service name drop-down menu automatically displays the SERVICE_NAME name in the tnsnames. ora file in the environment variable tns_admin, that is, the SID to be connected.
Userid
5. The test connection is successfully connected.
C #
Project-> Add reference->. Net-> system. Data. oracleclient. dll (This dll exists after installing DOTNET 1.1)
Using System;
Using System. Data;
Using System. Windows. forms;
Using System. Data. oracleclient;
Namespace Test
... {
/**/ /// <Summary>
///During the concise Period, the implementation is directly written in the constructor.
/// </Summary>
Public Class Test
... {
Public Test ()
... {
//
// Todo: add the constructor logic here
//
String Connectionstring = " Data Source = orcl; user id = Scott; Password = Scott " ; // Connection string
Oracleconnection Conn = New Oracleconnection (connectionstring ); // Create a new connection
Try
... {
Conn. open (); // Open connection
Oraclecommand cmd = Conn. createcommand ();
Cmd. commandtext = " Select * from EMP " ; // SQL statement
Oracledatareader rs = Cmd. executereader ();
While (Rs. Read ()) // Read data. If Rs. Read () returns false, it indicates the end of the record set.
... {
MessageBox. Show (Rs. getstring (1));
}
Rs. Close ();
}
Catch (Exception E)
... {
MessageBox. Show (E. Message );
}
Finally
... {
Conn. Close ();
}
}
}
}