Tuesday, February 15, 2011

Oracle Connection with Visual Studio 2010

Pretty Simple Huh? not really.

here are the common tasks that you would like to do

(LINQ to SQL and entity framework not supported – Don’t even try it)

a. Connect the DB from VS to run some selects.

b. Create connection in code and get some data on web page.

There are 3 ways to go

1. Client side – System.data.OracleClient –> this is going away soon. so don not build you fortune apps on this. However, Visual studio uses this to connect. here is what you need (learned hard way)

  • Open VS, Data->Add new data source and select Dataset.
  • In add new connection dialog, you need to know the Host name of the Oracle server. (typically “HOST=” in your tnsnames.ora – on Oracle server)
  • you also need to know the SID which is nothing but the service ID. (typically “SERVICE_NAME=” in your tnsnames.ora – on Oracle server)

image

  • make sure that you enter servername/SID and use the test connection. – Success!

2. ODP.NET – oracle Data provider for .NET – a world in itself. More details and downloads here

http://www.oracle.com/technology/sample_code/tech/windows/odpnet/howto/connect/index.html

<- Note that this is the way to go. make sure that you do connection pooling to save money on performance consultant Smile

3. .NET data provider for Oracle – From .NET side. pretty much OLEDB stuff. Didn’t go good on performance front for Obvious reasons, last choice for me.