首页 > 代码库 > C#代码访问oracle数据库

C#代码访问oracle数据库

1 引用System.Data.OracleClient

         路径:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.OracleClient.dll

2 安装Oracle client

1 官网下载

win32_11gR2_client.zip

注意版本及安装步骤。

2配置文件 sqlnet.ora tnsnames.ora

路径:本机为: D:\app\Administrator\product\11.2.0\client_1\network\admin\sqlnet.ora

注意oracle client的安装路径

内容

sqlnet.ora:

                   SQLNET.AUTHENTICATION_SERVICES= (NONE)

NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)

tnsnames.ora:

SDEORCL =

  (DESCRIPTION =

    (ADDRESS_LIST =

      (ADDRESS = (PROTOCOL = TCP)(HOST = VASTSCENE_XP_01)(PORT = 1521))

    )

    (CONNECT_DATA =http://www.mamicode.com/

           (SERVER = DEDICATED)

      (SERVICE_NAME = sdeorcl)

    )

  )

 

SDE =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = VASTSCENE_XP_01)(PORT = 1521))

    (CONNECT_DATA =http://www.mamicode.com/

      (SERVER = DEDICATED)

      (SERVICE_NAME = orcl)

    )

  )

 

ORCL =

  (DESCRIPTION =

    (ADDRESS_LIST =

      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.20)(PORT = 1521))

    )

    (CONNECT_DATA =http://www.mamicode.com/

      (SERVICE_NAME = orcl)

    )

)

3 安装PLSQL Developer

 

若成功则能够连接成功

 

服务器开启但无法成功连接(即能够ping通,但无法访问SDE)

可能原因:

服务器没有启动SDE 以及ORACLE相关服务

解决方法

启动oracle sde相关服务:

cmd->services.msc 将arcsde服务启动,将oracle相关服务启动

C#代码访问oracle数据库