The code is as follows |
|
Connectionstring= "PASSWORD=CZH; User id=czh;data source= (description= address_list= (address= (protocol=tcp) (host=192.168.168.211) (PORT=1521)) ( Connect_data= (server=dedicated) (Service_name=skydream)); " |
HOST: Server IP or server name
Service_name:oracle Data Name
User Id:oracle username
Password:oracle User Password
If the Oracle database and the Web can be written on the same server
Connectionstring= "PASSWORD=CZH; User id=czh;data Source=skydream; "
Now we're going to start querying the data,
Preparatory work:
A, install Oracle Client. I have an Oracle 10g installed. If you use the data Source=ip address, you must install the client
1, add references in. NET System.Data.OracleClient
2, define the connection mode (bound data to the GridView): String strconn= "Data Source=ip address;" User id= account number; password= password ";
The code is as follows |
|
OracleConnection conn=new OracleConnection (strconn); ---instantiating a connection Conn.Open (); String Strsql= "select * from Table"; OracleDataAdapter da=new Oracle DataAdapter (strsql,conn); DataTable dt=new DataTable (); Da. Fill (DT); Conn. Close (); GRIDVIEW1.DATASOURCE=DT; Gridview1.databind (); |
The binding was successful.
B, if you do not have Oracle client installed, see from some data to be able to use:
The code is as follows |
|
String strconn= "Data source=" ( DESCRIPTION = (Address_list = (address = (PROTOCOL = TCP) (HOST = *.*.*.*) (PORT = * *)) ) (Connect_data = (service_name = service name) ) ); |
User id= account number; password= password; "; -----not validated
B, about the centralized way to read the database:
1.1, is the example of a
UPDATE, insert Update query Oracle database content *
The code is as follows |
|
OracleConnection conn=new OracleConnection (strconn); Conn.Open (); String strsql= "Update tabel1 set column1= ' where ..."; or strsql= "INSERT into table1 values (', ')"; OracleCommand ocd=new OracleCommand (strsql,conn); int INTRESULT=OCD. ExecuteNonQuery (); Conn.closed (); |
Read query Oracle database content
The code is as follows |
|
String strsql= "SELECT * from Tblproject"; OracleCommand cmd=new OracleCommand (strsql,conn); OracleDataReader Dr=cmd. ExecuteReader (); If (Dr. Read ()) {......} Cmd. Dispose (); Dr. Dispose (); Conn. Closed (); |
I've had some problems with the connection, and I'll share them with you. Error connecting Oracle
When a component that uses data access in a asp.net application (call System.Data.OracleClient), the program reports "System.Exception:System.Data.OracleClient requires Oracle Client software version 8.1.7 or greater error, unable to create OracleConnection.
A when ORACLE 9.2 is running on an NTFS partition, the Oracle_home directory is not visible to users of some non-administrator groups, and the account used for ASP.net applications under Windows Server 2003 is Netword Service, so you cannot create an Oracle connection, just reset the permissions on the Oracle_home directory.
The steps are as follows:
1, the user login to the administrator;
2, Find Oracle_home folder (my is d:oracleora92, do not modify the Oracle folder, because the Oracle_home folder is the Ora92 folder under Oracle), right click, select Properties-Security, Select "Authenticated Users" in the group or user column to remove the "read and run" permission in the following list of permissions, click Apply, and then select "Read and Run" permissions, select the "Advanced" button below the permission box to confirm "authenticated Users" "The following application then" This folder, subfolders and files, as determined by the change of permissions to apply to the folder;
3, restart the computer, so that the permissions settings take effect (in fact, only need to restart IIS can);
4, after the login run asp.net application, the normal access to Oracle database data.