首先要保持两台计算机是连接状态的;

当前项目要添加两个引用一个是system data oracleclient,一个是system configuration;

配置文件中:

<connectionStrings>
    <!--连接远远程,注意datasource连接的是数据库服务的别名自己可以改,连接端计算机也可以改注意名称与本地的服务名一致-->
    <!--<add name="orcon" connectionString="Data Source=8;Persist Security Info=True;User ID=bing;Password=abing520;Unicode=True" providerName="System.Data.OracleClient"/>-->
    <!--连接本机数据库-->
    <add name="orcon" connectionString="Data Source=orcl;Persist Security Info=True;User ID=hb;Password=hb;Unicode=True" providerName="System.Data.OracleClient"/>

  </connectionStrings>

 

cs文件中:

string constr = ConfigurationManager.ConnectionStrings["orcon"].ConnectionString;
            OracleConnection conn = new OracleConnection(constr);
            OracleCommand cmd = conn.CreateCommand();
            conn.Open();
            cmd.CommandText = "select * from dinger";
            OracleDataAdapter ad = new OracleDataAdapter(cmd);
            DataTable dt = new DataTable();
            ad.Fill(dt);
            cmd.Dispose();
            conn.Dispose();
            Response.Write(dt.Rows[0]["NAME"]);