VS2013需要和Oracle数据库交互,新装本地Oracle数据库,安装了此ODTwithODAC112030,以下是安装步骤:
准备工作:
1.安装好Oracle数据库,倾听文件路径:D:\app\Administrator\product\11.2.0\dbhome_1\NETWORK\ADMIN
2.安装好ODAC121012Xcopy_32bit和ODAC121012Xcopy_64bit(没有足够证据证明一定要此步骤,但是我事先安装了,方法参考上一篇文章)
安装步骤:
1.在ODTwithODAC112030文件夹中,直接setup.exe,一直下一步到:
路径我仅仅只是修改了盘符为C盘。
2.然后一直下一步,安装好之后应用一下系统变量。具体为:
PATH = C:\app\Administrator\product\11.2.0\client_2;C:\app\Administrator\product\11.2.0\client_2\bin;D:\app\Administrator\product\11.2.0\dbhome_1\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\
3.添加其他系统变量:
(1)变量名:TNS_ADMIN 变量值:C:\app\Administrator\product\11.2.0\client_2\Network\ADMIN
(2)变量名:NLS_LANG 变量值:SIMPLIFIED CHINESE_CHINA.ZHS16GBK
(3)如果安装后没有添加Path系统变量,则此处添加: 变量名:Path 变量值:C:\app\Administrator\product\11.2.0\client_2\bin;C:\app\Administrator\product\11.2.0\client_2;D:\app\Administrator\product\11.2.0\dbhome_1\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\
4.将服务端network添加到客户端,具体为:
将D:\app\Administrator\product\11.2.0\dbhome_1\NETWORK直接覆盖C:\app\Administrator\product\11.2.0\client_2\NETWORK,可以将客户端的备份一下
5.配置文件D:\app\Administrator\product\11.2.0\dbhome_1\NETWORK\ADMIN\tnsnames.ora:
# tnsnames.ora Network Configuration File: D:\app\Administrator\product\11.2.0\dbhome_1\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.
LISTENER_ORCL =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
ORACLR_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
(CONNECT_DATA =
(SID = CLRExtProc)
(PRESENTATION = RO)
)
)
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
倾听文件:D:\app\Administrator\product\11.2.0\dbhome_1\NETWORK\ADMIN\listener.ora:
# listener.ora Network Configuration File: D:\app\Administrator\product\11.2.0\dbhome_1\network\admin\listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = CLRExtProc)
(ORACLE_HOME = D:\app\Administrator\product\11.2.0\dbhome_1)
(PROGRAM = extproc)
(ENVS = "EXTPROC_DLLS=ONLY:D:\app\Administrator\product\11.2.0\dbhome_1\bin\oraclr11.dll")
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
)
)
ADR_BASE_LISTENER = D:\app\Administrator
配置文件:D:\app\Administrator\product\11.2.0\dbhome_1\NETWORK\ADMIN\sqlnet.ora:
# sqlnet.ora Network Configuration File: D:\app\Administrator\product\11.2.0\dbhome_1\network\admin\sqlnet.ora
# Generated by Oracle configuration tools.
# This file is actually generated by netca. But if customers choose to
# install "Software Only", this file wont exist and without the native
# authentication, they will not be able to connect to the database on NT.
SQLNET.AUTHENTICATION_SERVICES= (NTS)
NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)
6.tnsping orcl用来测试数据库监听文件是否配置正确
7.打开VS2013,工具 ---- 连接到数据库 ---- 数据库连接 ---- 添加连接:
8.报错:ORA-12154(TNSNAMES.ORA配置不正确,或者位置放得不正确)
解决方法:重启电脑,让环境变量等生效。
9.重启电脑后,再次对VS2013连接Oracle,大功告成。
10.C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config和C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config两个文件里面的配置修改,参考上一篇文章。如果这两个文件不能正确配置,依旧不能再程序中修改数据库。