.NET WIN7 64位 连接Oracle数据库

先右击项目,添加引用。COM选项卡下搜System.Data.OracleClient这个。引用到项目里。
如果下方代码报 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);
        }

       
    }
}


posted @ 2016-07-29 14:08  离。  阅读(25)  评论(0编辑  收藏  举报