Jump to content
xisto Community
Sign in to follow this  
Nik

Asp.net & Oracle Connectivity Can I connect ASP.NET with Oracle 11g

Recommended Posts

Actually I am new in this ASP.NET programming. Can I use Oracle 11g software for connecting database to the ASP.NETI want to make e-shopping website and My database contains huge data so I opted for Oracle 11g. So can I connect ASP.NET to Oracleif yes then give me code to connect it.

Share this post


Link to post
Share on other sites

Sure you can! I hooked up my ASP.NET application to an Oracle 11g database and it's heavily integrated with the Oracle database such that I can't pull it apart and hook it up to another database right now.

What? ASP.NET doesn't work with Oracle? OMG! Hang on, I've got to go cancel my order for a new pair of JBL speakers... I'm not getting my paycheck till the application I built works and this is going to take a whole re-write of my code.... No, not really, just kidding! ASP.NET does work with Oracle and my paycheck is on its way.

So, anyway, back to hooking up ASP.NET to Oracle. When I installed the Oracle database (I didn't settle for the Express edition cheapness... I went all the way and installed the real deal, since we had a development license lying around someplace), I got the database server and all the client libraries to go with it, and that includes the ODP.NET (Oracle Data Provider for .NET) and ODAC (Oracle Data Access Components?).

After installing all the needful (the Oracle database, ODAC, and ODP.NET), you have to add a reference to the Oracle data access library (Add Reference through Visual Studio and select Oracle.DataAccess... if it is not in the Global Assembly Cache, browse for it and select Oracle.DataAccess.dll).

Within your code, create a new instance of the OracleConnection class (located within the Oracle.DataAccess.Client namespace) and pass in the connection string as a parameter (the connection string would look something like "Data Source=ORCL; User ID=scott; Password=tiger". Then, call the Open method on the OracleConnection object and there you go! You have a connection to the Oracle database. Then, create an OracleCommand object by calling the CreateCommand method of the OracleConnection object, set the CommandText property to something like "DELETE FROM dept WHERE deptno = 20" and set the CommandType to CommandType.Text (an enumeration; these are a kind of class constants that are used to specify options to methods instead of using true-false flags or integers that are codes to represent values). Then, call the ExecuteNonQuery method on the OracleCommand object and watch department number 20 disappear from the database! Make sure you call the Close method on the OracleConnection object and if you figure out that the DML (Data manipulation language, a subset of the Structured Query Language) isn't taking effect, make sure that you've set the AutoCommit property on the connection to True.

That's all there is to it!


Actually I am new in this ASP.NET programming. Can I use Oracle 11g software for connecting database to the ASP.NETI want to make e-shopping website and My database contains huge data so I opted for Oracle 11g. So can I connect ASP.NET to Oracle
if yes then give me code to connect it.


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.