如果下方代码报 ORA-06413连接未打开的错误。请参考我上篇日志
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using EIPWebService.Entity;
using System.Data;
using System.Data.SqlClient;
using ADODB;
using EIPWebService.DAL;
using System.Data.OracleClient;
namespace EIPWebService
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string oradb = "Data Source=(DESCRIPTION="
+ "(ADDRESS=(PROTOCOL=TCP)(HOST=数据库IP地址)(PORT=1521))"
+ "(CONNECT_DATA=(SERVICE_NAME=数据源服务名)));"
+ "User Id=数据库登录名;Password=密码;";
OracleConnection conn = new OracleConnection(oradb);
//OracleConnection conn = new OracleConnection();
conn.ConnectionString = oradb;
conn.Open();
string sql = " select * from 表名 where 列名 ='10000' ";
OracleCommand cmd = new OracleCommand(sql, conn);
cmd.CommandType = CommandType.Text;
OracleDataReader dr = cmd.ExecuteReader(); // C#
dr.Read();
string aa = dr["字段名"].ToString();
conn.Close(); // C#
conn.Dispose(); // C#
Response.Write(aa);
}
}
}