Connect to Oracle using ASP.Net and C# or VB.Net
- 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:
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=TCP)(HOST=OTNSRVR)(PORT=1521))
)
(CONNECT_DATA=
(SERVER=DEDICATED)
(SERVICE_NAME=ORCL)
)
)
- 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:
- 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.
No comments:
Post a Comment