Click here to Skip to main content
15,880,543 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
Hi all ,
we have some oracle applications running on an oracle application server and we have other web application that running on other servers and SQL server too, so mainly what i want to ask about :- is there any way to write a web application that can connect to oracle database on a 64bit machine using VS 2010, that can migrate and retrieve data from Oracle Database to SQL server ??

Thank you so much.
Posted
Updated 25-Apr-19 3:00am

1 solution

Add ref to System.Data.OracleClient and define your connection.

C#
using System.Data.OracleClient;


C#
private static string CONNECTION_STRING =
  "User Id=myUserID;Password=myPassword;Data Source=(DESCRIPTION=" +
  "(ADDRESS=(PROTOCOL=TCP)(HOST=myserver.server.com)(PORT=yourPort#))" +
  "(CONNECT_DATA=(SID=yourSID)));";


C#
using (OracleConnection connection = new OracleConnection()) 
  { 
    connection.ConnectionString = CONNECTION_STRING; 
    connection.Open(); 
    Console.WriteLine("State: {0}", connection.State); 
    Console.WriteLine("ConnectionString: {0}", 
                      connection.ConnectionString); 
    
    OracleCommand command = connection.CreateCommand(); 
    string sql = "SELECT * FROM MYTABLE"; 
    command.CommandText = sql; 
 
    OracleDataReader reader = command.ExecuteReader(); 
    while (reader.Read()) 
    { 
      string myField = (string)reader["MYFIELD"]; 
      Console.WriteLine(myField); 
    }
  }
 
Share this answer
 
Comments
rushdi obeidat 26-Sep-12 2:50am    
hi, thank you so much for the solution , but when i tried it out the following error appears : - System.Data.OracleClient requires Oracle client software version 8.1.7 or greater.
Kuthuparakkal 26-Sep-12 3:08am    
Install Oracle Instant Client( instantclient-basiclite-nt-11.2.0.3.0.zip will do) :
http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
Once you install find the following dlls:
oraociicus10.dll
oci.dll
orannzsbb10.dll
oraocci10.dll

Copy the above 4 dlls into the same directory as your executable.
Rajesh Varatharajan 20-Jun-13 5:30am    
hi,
i tried the above but the following error came:

error C2039: 'OracleClient' : is not a member of 'System::Data'
CHill60 20-Jun-13 9:29am    
You must have a more recent version of VisualStudio than Kuthuparakkal - OracleClient has been deprecated. See this https://blogs.oracle.com/databaseinsider/entry/microsoft_deprecates_systemdataoracleclient_net_developers_for_oracle_should_migrate_to_oracle_data_provider_for_net[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900