- Category: C#
- Published on Tuesday, 06 January 2009 21:04
- Written by Shabdar
- Hits: 99255
- Create a new project in Visual Studio using eight C# or VB.Net
- Add reference to Oracle.DataAccess.dll file. Typically this file can be found in C:\oracle\product\10.2.0\client_1\BIN directory. This directory may be different based on your oracle configuration.
- Once library is referenced, go to your class file where you want to create oracle connection.
- Add following statements based on language you selected for project.
- An Oracle connection string is inseparable from Oracle names resolution. Suppose we had a database alias of OraDb defined in a tnsnames.ora file as follows:
- The OraDb alias defines the database address connection information for the client. To use the OraDb alias defined in the tnsnames.ora file shown above, you would use the following syntax:
- You can modify the connection string to obviate the need for the tnsnames.ora file, however. Simply replace the name of the alias with how it would be defined in a tnsnames.ora file.
- Now you can create connection object from the connection string above. The connection string must be associated with the connection object.
- Now you can use this connection like any other connection and do various database tasks.
- To open a connection, use following statements,
- To create a command object, use following statements,
- You can retrieve values from command object using following statement,
- All open connection objects should be closed once you are done using them.