• C#连接Oracle数据库字符串(引入DLL)


    https://www.cnblogs.com/chenyanbin/p/11324614.html

    需求:从一台Oracle数据库获取数据,本以为是很简单的事情,直接将原来的SqlClient换成OracleClient调用,结果远没自己想的简单。要么安装Oracle客户端,要么安装PLSQL。网上这方面搜索后,太多的文章,还要不停的去测试。最后找个引入外部类库的方式。这个DLL其实是Oracle为C#专门提供的,在它的官方也可以下载到(不过找起来很麻烦)。

    这里我就把这个方案和dll分享给大家。

    链接:https://pan.baidu.com/s/17saKNnBVyDvMbt1L8lSf6A
    提取码:sr97

    DEMO示例#

    复制代码
    using Oracle.ManagedDataAccess.Client; //引入命名空间
    
        </span><span style="color: rgba(0, 0, 255, 1)">private</span> <span style="color: rgba(0, 0, 255, 1)">void</span> button1_Click(<span style="color: rgba(0, 0, 255, 1)">object</span><span style="color: rgba(0, 0, 0, 1)"> sender, EventArgs e)
        {
            </span><span style="color: rgba(0, 0, 255, 1)">string</span> strSql = <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">select * from s_user</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">;
            DataTable dt </span>=<span style="color: rgba(0, 0, 0, 1)"> QueryDt(strSql);
        }
    

    //Oracle连接字符串
    private static string strconn = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=172.30.0.37)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=EMES)));Persist Security Info=True;User ID=EMES_DEV;Password=EMES_DEV;";

        </span><span style="color: rgba(0, 0, 255, 1)">private</span> DataTable QueryDt(<span style="color: rgba(0, 0, 255, 1)">string</span><span style="color: rgba(0, 0, 0, 1)"> sql)
        {
            </span><span style="color: rgba(0, 0, 255, 1)">using</span> (OracleConnection conn = <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> OracleConnection(strconn))
            {
                </span><span style="color: rgba(0, 0, 255, 1)">try</span><span style="color: rgba(0, 0, 0, 1)">
                {
                    </span><span style="color: rgba(0, 0, 255, 1)">if</span> (conn.State !=<span style="color: rgba(0, 0, 0, 1)"> ConnectionState.Open)
                    {
                        conn.Open();
                    }
                    OracleDataAdapter adap </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> OracleDataAdapter(sql, conn);
                    DataTable dt </span>= <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> DataTable();
                    adap.Fill(dt);
                    </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> dt;
                }
                </span><span style="color: rgba(0, 0, 255, 1)">catch</span><span style="color: rgba(0, 0, 0, 1)"> (Exception ex)
                {
                    </span><span style="color: rgba(0, 0, 255, 1)">return</span> <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">;
                }
                </span><span style="color: rgba(0, 0, 255, 1)">finally</span><span style="color: rgba(0, 0, 0, 1)">
                {
                    conn.Close();
                }
            }
        }</span></pre>
    
    复制代码

    连接字符串格式:#

    复制代码
    1 格式:
    2 string strconn = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=172.30.0.37)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=EMES)));Persist Security Info=True;User ID=EMES_DEV;Password=EMES_DEV;";
    3 
    4 格式:
    5 string strconn = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=远程服务器IP地址)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=远程服务器数据库服务名称)));Persist Security Info=True;User ID=数据库用户名;Password=数据库密码;";
    复制代码

    远程服务器数据库服务名称如下:#

    效果:#

     

  • 相关阅读:
    Random简介
    十道海量数据处理面试题
    Django models 的字段类型
    执行monkey APK 制作
    MTK平台-抓取蓝牙log
    超级硬件代理解决企业Web提速上网问题
    Red Hat Linux 安装 (本地、网络安装)
    由安装两块网卡的linux系统中引起网络不通想到的
    Linux企业应用--RHAS 2.1 下安装中文 Lotus Domino R 6.5 图解
    巧用Linux 架设TFTP Server备份路由器的配置文件
  • 原文地址:https://www.cnblogs.com/sunny3158/p/14701525.html
Copyright © 2020-2023  润新知