First, let's take a look at some of my environments,
The operating system is the flagship version of win 7,
Oracle 10g R2,
Visual Studio is Visual Studio 2008,
All of the preceding descriptions are completed by manually writing the Oracle database connection string to access the Oracle database,
This section describes three methods: oracleclient, oledb, and ODBC,
In fact, Oracle operations are not as complicated as imagined,
Especially when Oracle provides some plug-ins under Visual Studio, it is easier to use them,
This makes your operations on Oracle in vs similar to those on SQL Server,
In fact, vs provides three types of data for Oracle access.Program,
One is the. NET Framework data provider for Oracle.
One is:. NET Framework data provider for oledb
One is: Oracle data provider for. net
In the third case, you must first install ODP. Net provided by Oracle to achieve access,
This will be introduced in the following blog,
It must be mentioned that to access the Oracle database in,
You must configure the Oracle database first,
Some common configuration errors are mainly caused
D: \ oracle \ product \ 10.2.0 \ db_1 \ Network \ admin
Configuration of two files in this directory
The configuration of these two files is crucial. The Listener. ora is the information of the listener service specified by the user,
If the file is set incorrectly, the listener may fail to start,
For simplicity, cut down the items in the image directly,
It is mainly to set the host,
Then you need to configureTnsnames. ora
This file is also very important. It directly involves whether your vs or application can access the Oracle database,
The setting description is that the host is used to specify the host name or IP address of the Oracle server,
SERVICE_NAME specifies the global database name,
Generally, after the following two steps, you can determine whether the preceding two files are correctly set,
First, after you have set the above two files, you can restart the listening service,
If the listening service can be started properly, it indicates the configuration fileListener. oraThe configuration is basically correct,
Then, you can use the tnsping database name to determineTnsnames. oraIs the configuration correct,
For example, my global database name is Oracle,
I will judge through tnsping OracleTnsnames. oraIs the configuration correct,
If a similar result is obtained, it indicates that the configuration file is correct,
Now let's look at the two methods above,
Then I create a new connection
Change the data source (first use "user oracle's. NET Framework data provider ")
Oracle is used to specify the name of the Oracle database to be connected.
You can see
Let's take a look at a demo to test the above settings.
Demo is simple: Put A gridview on a page,
Then, bind all the data in the EMP table in Oracle. Scott to display the data,
You can check the effect directly.
--------------------------------------------- Gorgeous separation line -----------------------------------------
--------------------------------------------- Gorgeous separation line -----------------------------------------
--------------------------------------------- Gorgeous separation line -----------------------------------------
The preceding section describes how to use the first data provider to access Oracle,
Next, we will introduce the. NET Framework data provider for oledb.
Add a connection to the Oracle database as before,
However, the data provider used this time is used for the. NET Framework data provider of oledb.
I still use Scott users to access the Oracle database,
After the connection is successful, you can see
Let's look at a demo to access the Oracle database through the database connection.
This demo is no different from the previous demo. You can access Oracle to obtain data in the EMP table,
This is not a demonstration here,
The last method is to use ORACLE data provider for. net,
It can be completed through Oracle Developer Tools for Visual Studio. NET,
Will be introduced later !!!