admin

Oracle与SQL Server的数据库连接

admin Tomcat 2023-02-27 1046浏览 0

Software:

SQL Server 2005 (win 2003)
Oracle 10gR2 (Redhat AS 4 update 2)

1. isntall 10201_client_win32.zip under D:\oracle

if the D: drive is NTFS you have to give ALL rights to the user

2. listener.ora and tnsnames.ora
$ e /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora

……………………………………

SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = ETMCDB)
(ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
(SID_NAME = ETMCDB)
# (PROGRAM = extproc)
)
)

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.1.106)(PORT = 1521))
)
)

……………………………………

e D:\oracle\product\10.2.0\client_1\NETWORK\ADMIN\tnsnames.ora

……………………………………

Link_Ora =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.1.106)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = ETMCDB)
)

)
……
………………………………
D:\oracle\product\10.2.0\client_1\BIN>tnsping Link_Ora
TNS Ping Utility for 32-bit Windows: Version 10.2.0.1.0 – Production on …………………………

D:\oracle\product\10.2.0\client_1\BIN>sqlplus system/oracle@Link_Ora
SQL*Plus: Release 10.2.0.1.0 – Production on …………………………
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 – Production
With the Partitioning, OLAP and Data Mining options
SQL>
Start –> Control Panel–> Services: to make sure “Distributed Transaction Coordinator” is starting

3. windows ODBC
Start –> Control Panel –> Computer Management –> ODBC –> Tab (User DNS or System DNS) –> Add (
Microsoft ODBC for oracle) –> Name (Same as the name in tnsnames.ora:Link_Ora) –> Server name (Same as the name in tnsnames.ora:Link_Ora)–>Finish

4. DB_Link in SQL Server
In General Tab

Link_

Name:
Other Data Source
Link: Microsoft OLE DB Provider for Oracle
Product name: Oracle
Data_Source: the Name in ODBC Link_Ora(step 3)
User ID=username;Password=userpasswd or UID=username;PWD=userpasswd (the username / password in Oracle)

In Security Tab:

Select the last option: enter the username / password in Oracle


Or to use SQL:

ADD:

EXEC sp_addlinkedserver ‘Link_Ora’, ‘Oracle’, ‘Link_Ora‘, ‘Server name or IP’
EXEC sp_addlinkedserver ‘Link_Ora’, ‘Oracle’, ‘Link_Ora‘, ‘ETMCDB’

EXEC sp_addlinkedsrvlogin @rmtsrvname=’Link_Ora’,@useself=’false’,@locallogin=’sa’,@rmtuser=’sys’,@rmtpassword=’oracle’
or
Link_Ora‘,’false’,null,’rmtuser‘,’rmtpassword

DEL:

IF EXISTS (SELECT srvname FROM master.dbo.sysservers srv WHERE srvid != 0 AND srvname = N’DB_Link_Name’)
EXEC master.dbo.sp_dropserver @server=N’DB_Link_Name’, @droplogins=’droplogins’


Testing:

SELECT * FROM Link_Ora.ERP.BAS_ITEM_CLASS
SELECT * FROM openquery(OraTest,’SELECT * FROM OraTest.ERP.BAS_ITEM_CLASS ‘)

Ref:

http://www.west263.com/www/info/50399-1.htm
http://www.cnblogs.com/jjiac/archive/2008/07/03/1234643.html
http://www.mssqlcity.com/FAQ/Replic/LinkSetRepl.htm

http://www.cnblogs.com/studyzy/archive/2006/12/08/690307.html
http://space.itpub.net/?uid-7728585-action-viewspace-itemid-470225

继续浏览有关 数据库技术文章/教程 的文章
发表评论