Before using Oracle, you have to install his bloated client, although the Internet also provides direct-to-Oracle driver, but also to charge, recently Oracle finally enlightened, provide the official full-managed drive.
This is the Oracle all-managed driver included with the Oracle ODAC 12c release package, and Oracle has released two beta versions of the fully managed driver, but some problems have been identified in the test, and the 12.1.0.1.0 of this release Seems to have been released the official version, after a simple test, the last version of the bug I encountered has been fixed, there is no new problems found, recommend everyone to use.
: http://www.oracle.com/technetwork/topics/dotnet/downloads/index.html
Method One:
123456789101112131415161718192021222324252627282930313233343536373839404142 |
using System; using System. Collections. Generic; using System. Linq; using System. Text; using Oracle. Manageddataaccess. Client; using Oracle. Manageddataaccess. Types; namespace ConsoleApplication1 { class Program { static void Main(string[] args) /c10> { string strconn = "User id=test;password=test;" + "Data source= (description= (address= (protocol=tcp) (host=192.168.120.1) (port=1521)) (C Onnect_data= (server=dedicated) (SERVICE_NAME=ORCL))); " + "Pooling=false;" ; using (oracleconnection con = new oracleconnection( C16>strconn)) { con. Open(); string strsql = "SELECT * from the USERS order by ID"; oraclecommand cmd = new oraclecommand(strsql, Con); oracledatareader reader = cmd. ExecuteReader(); While (reader. Read()) { string Line = ""; for (int i = 0; Span class= "crayon-v" >i < reader. Fieldcount; i++) {Line += Reader.getname (i) tostring ( + "=" + reader.getvalue (i) tostring ( + } Console. WriteLine(line); } } Console. ReadLine(); } }} |
Method Two:
Modify the connection string to
123 |
string strconn = "User id=test;password=test;" + "Data source=192.168.120.1:1521/orcl;" + "Pooling=false;" ; |
This is a simple notation, but it doesn't work if you have multiple addresses.
Method Three:
In the downloaded oracle.manageddataaccess package, there is a Tnsnames.ora file under the \network\admin\sample directory, modify the listener information for this file configuration database, and copy the file to the application root directory.
123 |
string strconn = "User id=test;password=test;" + "Data source=test;" + "Pooling=false;" ; |
Oracle official full-managed driver oracle.manageddataaccess 12.1.0.1.0