Oracle9i connection ASP.net method and attention point

Source: Internet
Author: User
Tags oracleconnection
Asp.net|oracle #region Statement
//----------------------------------------------------------------------
//
Modified: Li Miao (nick.lee)
//
Oracle9i connection ASP.net method and attention point

Time: 2005-3-18

Boyorgril@msn.com
qq:16503096
Note: Please indicate the source of the change, thank you
//----------------------------------------------------------------------
#endregion

Recommended Way

public void Oledboracle_dataset ()
{
String connectionstring= "Data source=mine;user=sys;password=sys;"; Write connection string
OracleConnection conn=new OracleConnection (ConnectionString); Create a new connection
OracleCommand cmd= New OracleCommand ("SELECT * from Fjdl.t_rights", conn);
DataSet ds = new DataSet ();
OracleDataAdapter oda=new OracleDataAdapter ();
Oda. Selectcommand=cmd;
Oda. Fill (DS);
Conn. Close ();
Datagrid1.datasource=ds. Tables[0]. DefaultView;
Datagrid1.databind ();
}

The following are four methods for using datasets and Datareader,oledb and Oralceclient

public void Oledboracle_datareader ()
{
System.Data.OleDb.OleDbConnection oledb1=new System.Data.OleDb.OleDbConnection ();
String sqltext= "select * from Scott.tadmin";
System.Data.OleDb.OleDbDataReader reader;

OLEDB1. connectionstring= "provider=\" oraoledb.oracle.1\ "; User id=system;password=system;data Source=rick; ";
System.Data.OleDb.OleDbCommand com=new System.Data.OleDb.OleDbCommand (SQLTEXT,OLEDB1);

Com.Connection.Open ();
Reader=com.executereader ();

Datagrid1.datasource=reader;
Datagrid1.databind ();

This. Response.Write (oledbconnection1.connectionstring);
Reader. Close ();
Com.Connection.Close ();
}
public void Oledboracle_dataset ()
{
System.Data.OleDb.OleDbConnection oledb1=new System.Data.OleDb.OleDbConnection ("provider=\" oraoledb.oracle.1\; User id=system;password=system;data Source=rick; ");
String sqltext= "select * from Scott.tadmin";
System.Data.DataSet set1=new DataSet ();
System.Data.OleDb.OleDbDataAdapter ada1=new System.Data.OleDb.OleDbDataAdapter (SQLTEXT,OLEDB1);
Ada1.fill (Set1, "data1");

This. Datagrid2.datasource=set1. tables["Data1"]. DefaultView;
This. Datagrid2.databind ();
}
public void Oracle_dataset ()
{
System.Data.OracleClient.OracleConnection oracle1=new System.Data.OracleClient.OracleConnection ("User id=system; Data Source=rick;password=system ");
String sqltext= "select * from Scott.tadmin";
System.Data.DataSet set1=new DataSet ();
System.Data.OracleClient.OracleDataAdapter ada1=new System.Data.OracleClient.OracleDataAdapter (sqltext,oracle1);
Ada1.fill (Set1, "oracle_data1");

This. Datagrid3.datasource=set1. tables["Oracle_data1"]. DefaultView;
This. Datagrid3.databind ();
}
public void Oracle_datareader ()
{
System.Data.OracleClient.OracleConnection oracle2=new System.Data.OracleClient.OracleConnection ();
String sqltext= "select * from Scott.tadmin";
System.Data.OracleClient.OracleDataReader reader;

Oracle2. connectionstring= "User id=system;user id=system;data Source=rick;password=system";
System.Data.OracleClient.OracleCommand com=new System.Data.OracleClient.OracleCommand (sqltext,oracle2);

Com.Connection.Open ();
Reader=com.executereader ();

Datagrid4.datasource=reader;
Datagrid4.databind ();

This. Response.Write (oledbconnection1.connectionstring);
Reader. Close ();
Com.Connection.Close ();
}

Note the point:

If you do not set the network configuration for remote data at this level

ora-00162:external dbid length is greater than maximum (16)

Connection name cannot exceed 16 characters

Modify method

Configuration in Configuration and migration tools->net Configuration Assistant





Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.