C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

Connect oracle Database without no install client oracle Using C#.net


Posted Date: 23 Oct 2009    Resource Type: Articles    Category: .NET Framework
Author: LaljiMember Level: Diamond    
Rating: 1 out of 5Points: 7



This article demonstrates in a step by step fashion the easiest, and frankly fastest way to connect

Step:1
Oracle has an Oracle Database Instant Client which is a set of Dlls which can be XCopy installed onto the development and target PC to allow Oracle database access without installing the full Oracle client. In future steps we will include those target Dlls to be copied to the target output folder with the executable. Download the appropriate package and add Dlls to a folder of your choice on the PC.

Step:2
Update: This step should not be done, for the dlls will end up being copied into a subfolder of the same name and when running the client an error may come up stating “System.Data.OracleClient requires Oracle client software
version 8.1.7 or greater”.

Step:3
Add the reference to the project of System.Data.OracleClient to the project.

Step:4
In Studio again (highlight the project root) and from the right click menu select Add->Existing Item, and insert all the top level Oracle Dlls from step one into the folder; unless for some reason you need previous versions all those dlls at the top level should be fine. 

Step:5
Highlight all the inserted DLLs and select Properties to bring up the properties window. Change the Build Action to be Content and the Copy To Output Directory to be Copy If Newer. This allows the dlls to reside with the created executable program. By doing this it allows the program to run on another computer, as well as this one, that does not have the Oracle Client installed because all the Oracle specific dlls reside with the output executable.

Step:6
On the design view of the form add a button, label, binding source and a DataGridView. The names used for each in the example (Label as lbState, Binding Source as bsOracle and DataGridView as gvOracle).

Step:7
Create in the forms code a method to handle the connection string and add the target Oracle db/instance items (Note: Replace { xxx } including the curly braces the specifics to your db) 

Code
private string GenerateConnectionString()
{
return "Data Source=( DESCRIPTION = ( ADDRESS_LIST = ( ADDRESS = ( PROTOCOL = TCP )( HOST = {Insert Host Here} )( PORT = {Insert Port Here} ) ) )( CONNECT_DATA = ( SERVER = DEDICATED )( SERVICE_NAME = {Service Name Here } ) ) ); User Id= {DB ID Here}; Password = {Password Here};";
}


Step:8
------
In the button’s onclick event wire up the controls and access the Oracle database as such:
try
02.{
03. using ( OracleConnection connection = new OracleConnection( GenerateConnectionString() ) )
04. {
05. connection.Open();
06. lblState.Text = connection.State.ToString();
07.
08. OracleCommand oc = connection.CreateCommand();
09. oc.CommandText = "SELECT * FROM {Your Table Here}";
10.
11. OracleDataReader reader = oc.ExecuteReader();
12.
13. bsOracle.DataSource = reader;
14. gvOracle.DataSource = bsOracle;
15.
16. gvOracle.BorderStyle = BorderStyle.Fixed3D;
17. gvOracle.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
18.
19. }
20.}
21.catch ( Exception ex )
22.{
23.// MessageBox.Show( "Exception: " + ex.Message );
24. lblState.Text = ex.Message;
25.}


Step:9
---------
Run and compile the program and if all goes well it should attach…but there are other possible failure points see the next section as to a couple of them.



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Connect oracle Database without no install client oracle  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Print Controls Using VB.NET
Previous Resource: Mvc/mvp
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use