Home > Database > Mysql Tutorial > c#连接远程oracle数据库

c#连接远程oracle数据库

WBOY
Release: 2016-06-07 16:39:12
Original
1116 people have browsed it

主要有两种方法,一种是直接写连接字符串,令一种是将连接字符串下载web.config文件中,下面分别作说明: 直接将写连接字符串: private static string connstr = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=Mhost) (PORT=mport

主要有两种方法,一种是直接写连接字符串,令一种是将连接字符串下载web.config文件中,下面分别作说明:
直接将写连接字符串:

 private static string connstr = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=Mhost) 
(PORT=mport)))(CONNECT_DATA=(SERVICE_NAME=mywervicename)));Persist Security Info=True;User Id=myusername; 
Password=mypassword";
 private OracleConnection DBCONN = new OracleConnection(connstr);
Copy after login

将连接字符串写在web.config文件中

private static string connstr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
private OracleConnection DBCONN = new OracleConnection(connstr);
Copy after login

这种方式的话要在配置文件中加入下面的配置信息

然后就可以打开连接并查询数据了
如下面

  public void GetData()
        {
            if (DBCONN.State == ConnectionState.Closed)
            {
                DBCONN.Open();
                string quarystr = "select * from tablename";
                OracleCommand comm = new OracleCommand(quarystr, DBCONN);
                OracleDataReader reader;
                reader = comm.ExecuteReader();
                while (reader.Read())
                {
                    string str = "" + reader.GetString(1);
                }
            }
        }
Copy after login

转载请注明:逝去日子的博客 » c#连接远程oracle数据库

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template