zoukankan      html  css  js  c++  java
  • C#连接远程oracle连接字符串(已自我测试)

    注:usingSystem.Data.OracleClient; 需要在项目右键点击,选择 '添加引用' ,在 .NET 中选择该项..

    usingSystem;
    usingSystem.Collections.Generic;
    usingSystem.ComponentModel;
    usingSystem.Data;
    usingSystem.Drawing;
    usingSystem.Linq;
    usingSystem.Text;
    usingSystem.Windows.Forms;
    usingSystem.Data.OracleClient;
    namespaceAppneu
    {
        publicpartialclassFrmCnfTable:Form
        {
            publicFrmCnfTable()
            {
                InitializeComponent();
            }

            privatevoidbutton1_Click(objectsender,EventArgse)
            {
                #region 从region到endregion是手工写的。别的都是系统自动生成的

                stringconstring="Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.3.120) (PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=orcl)));Persist Security Info=True;User Id=wangjj; Password=wangjj";
                OracleConnectionconn=newOracleConnection(constring);//进行连接          

                try
                {
                    conn.Open();//打开指定的连接                  
                    OracleCommandcom=conn.CreateCommand();
                    com.CommandText="Select Sysdate From dual ";//写好想执行的Sql语句                  
                    OracleDataReaderodr=com.ExecuteReader();
                    while (odr.Read())//读取数据,如果返回为false的话,就说明到记录集的尾部了                   
                    {
                        label1.Text="远程数据库时间:"+odr.GetOracleDateTime(0).ToString();//获得远程数据库时间
                    }
                    odr.Close();//关闭reader.这是一定要写的 
                }
                catch
                {
                    MessageBox.Show("erro");//如果发生异常,则提示出错             
                }
                finally
                {
                    conn.Close();//关闭打开的连接             
                }
                #endregion

            }
        }


    }

  • 相关阅读:
    【剑指offer】不使用新变量,交换两个变量的值,C++实现
    【剑指offer】不用加减乘除做加法,C++实现
    【剑指offer】求1+2+…+n,C++实现
    【剑指offer】左旋转字符串,C+实现
    给记事本添加接口,并通过菜单来执行自定义的功能
    修改PE文件的入口函数OEP
    360搜集隐私程序员级分析,供方舟子及大众参考
    Android窃取用户信息新思路
    如何整治那些敢偷用你Wi-Fi的人
    保护WIFI无线网络的安全
  • 原文地址:https://www.cnblogs.com/watermarks/p/3615533.html
Copyright © 2011-2022 走看看