• 周一. 8月 15th, 2022

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

.NET连接Oracle数据库

admin

11月 28, 2021
<connectionStrings>
        <add name="oracle" connectionString="Data Source= (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = xxx.xxx.xxx.xxx)(PORT = xxxx))) (CONNECT_DATA = (SERVICE_NAME= xxxx) ));User ID=xxxx;Password=xxxx" providerName="System.Data.OracleClient" />
    </connectionStrings>
HOST = xxx.xxx.xxx.xxx为IP地址
PORT = xxxx为端口

SERVICE_NAME= xxxx为数据库名

User ID=xxxx;Password=xxxx为数据库用户名和密码


using Oracle.ManagedDataAccess.Client;
/// <summary>
        /// 传入ORACLE-SQL获取SqlDataReader
        /// </summary>
        /// <param name="sql"></param>
        /// <returns>OracleDataReader</returns>
        public static OracleDataReader GetOracleReader(string sqlconn, string sql)
        {
            OracleConnection conn = new OracleConnection(sqlconn);
            conn.Open();
            OracleCommand cmd = new OracleCommand(sql, conn);
            OracleDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            return reader;
        }

发表回复

您的电子邮箱地址不会被公开。