在Oracle裡設定訪問多個SQL Server(轉)
在Oracle裡設定訪問多個SQL Server(轉)[@more@]如何在Oracle裡設定訪問多個SQL Server資料庫?假設我們要在ORACLE裡同時能訪問SQL Server裡預設的pubs和Northwind兩個資料庫。
1、在安裝了ORACLE9i Standard Edition或者ORACLE9i Enterprise Edition的windows機器上(IP:192.168.0.2), 產品要選了透明閘道器(Oracle Transparent Gateway)裡訪問Microsoft SQL Server資料庫
ORACLE9I_HOME g4msqladmin下新寫initpubs.ora和initnorthwind.ora配置檔案.
initpubs.ora內容如下:
HS_FDS_CONNECT_INFO="SERVER=SQLSERVER_HOSTNMAE;DATABASE=pubs"
HS_DB_NAME=pubsHS_FDS_TRACE_LEVEL=OFF
HS_FDS_RECOVERY_ACCOUNT=RECOVER
HS_FDS_RECOVERY_PWD=RECOVER
initnorthwind.ora內容如下:
HS_FDS_CONNECT_INFO="SERVER=sqlserver_hostname;DATABASE=Northwind"
HS_DB_NAME=Northwind
HS_FDS_TRACE_LEVEL=OFF
HS_FDS_RECOVERY_ACCOUNT=RECOVER
HS_FDS_RECOVERY_PWD=RECOVER
$ORACLE9I_HOME etworkadmin 下listener.ora內容如下:
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)(PORT = 1521))
)
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = test9)
(ORACLE_HOME = d:oracleora92)
(SID_NAME = test9)
)
(SID_DESC=
(SID_NAME=pubs)
(ORACLE_HOME=d:OracleOra92)
(PROGRAM=tg4msql)
)
(SID_DESC=
(SID_NAME=northwind)
(ORACLE_HOME=d:OracleOra92)
(PROGRAM=tg4msql)
)
)
重啟動這臺做gateway的windows機器上(IP:192.168.0.2)TNSListener服務.
(凡是按此步驟新增可訪問的SQL Server資料庫時,TNSListener服務都要重啟動)
2、ORACLE8I,ORACLE9I的伺服器端配置tnsnames.ora, 新增下面的內容:
pubs =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)(PORT = 1521))
)
(CONNECT_DATA =
(SID = pubs)
)
(HS = pubs)
)
northwind =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)(PORT = 1521))
)
(CONNECT_DATA =
(SID = northwind)
)
(HS = northwind) )
儲存tnsnames.ora後,在命令列下
tnsping pubs
tnsping northwind
出現類似提示,即為成功
Attempting to contact (DESCRIPTION = (ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)
(PORT = 1521))) (CONNECT_DATA = (SID = pubs)) (HS = pubs))
OK(20毫秒)
Attempting to contact (DESCRIPTION = (ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)
(PORT = 1521)))
(CONNECT_DATA = (SID = northwind)) (HS = northwind))OK(20毫秒)
設定資料庫引數global_names=false。
設定global_names=false不要求建立的資料庫連結和目的資料庫的全域性名稱一致。global_names=true則要求, 多少有些不方便。
oracle9i和oracle8i都可以在DBA使用者下用SQL命令改變global_names引數
alter system set global_names=false;
建立公有的資料庫連結:
create public database link pubs
connect to testuser identified by testuser_pwd using 'pubs';
create public database link northwind
connect to testuser identified by testuser_pwd using 'northwind';
(假設SQL Server下pubs和northwind已有足夠許可權的使用者登陸testuser,密碼為testuser_pwd)
訪問SQL Server下資料庫裡的資料:
select * from stores@pubs;
...... ......select *
from region@northwind;
...... ......
3、使用時的注意事項
ORACLE透過訪問SQL Server的資料庫連結時,用select * 的時候欄位名是用雙引號引起來的。
例如:
create table stores as select * from stores@pubs;
select zip from stores;
ERROR 位於第 1 行:
ORA-00904: 無效列名
select "zip" from stores;
zip
-----
98056
92789
96745
98014
90019
89076
已選擇6行
用SQL Navigator或Toad看從SQL Server轉移到ORACLE裡的表的建表語句為:
CREATE TABLE stores
("stor_id" CHAR(4) NOT NULL,
"stor_name" VARCHAR2(40),
"stor_address" VARCHAR2(40),
"city" VARCHAR2(20),
"state" CHAR(2),
"zip" CHAR(5))
PCTFREE 10
PCTUSED 40
INITRANS 1
MAXTRANS 255
TABLESPACE users
STORAGE (
INITIAL 131072
NEXT 131072
PCTINCREASE 0
MINEXTENTS 1
MAXEXTENTS 2147483645
)
/
總結:
WINDOWS下ORACLE9i閘道器伺服器在$ORACLE9I_HOME g4msqladmin目錄下的initsqlserver_databaseid.ora
WINDOWS下ORACLE9i閘道器伺服器listener.ora裡面
(SID_DESC=
(SID_NAME=sqlserver_databaseid)
(ORACLE_HOME=d:OracleOra92)
(PROGRAM=tg4msql)
)
UNIX或WINDOWS下ORACLE8I,ORACLE9I伺服器tnsnames.ora裡面
northwind =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)(PORT = 1521))
)
(CONNECT_DATA =
(SID = sqlserver_databaseid)
)
(HS = sqlserver_databaseid)
)
sqlserver_databaseid一致才行.
1、在安裝了ORACLE9i Standard Edition或者ORACLE9i Enterprise Edition的windows機器上(IP:192.168.0.2), 產品要選了透明閘道器(Oracle Transparent Gateway)裡訪問Microsoft SQL Server資料庫
ORACLE9I_HOME g4msqladmin下新寫initpubs.ora和initnorthwind.ora配置檔案.
initpubs.ora內容如下:
HS_FDS_CONNECT_INFO="SERVER=SQLSERVER_HOSTNMAE;DATABASE=pubs"
HS_DB_NAME=pubsHS_FDS_TRACE_LEVEL=OFF
HS_FDS_RECOVERY_ACCOUNT=RECOVER
HS_FDS_RECOVERY_PWD=RECOVER
initnorthwind.ora內容如下:
HS_FDS_CONNECT_INFO="SERVER=sqlserver_hostname;DATABASE=Northwind"
HS_DB_NAME=Northwind
HS_FDS_TRACE_LEVEL=OFF
HS_FDS_RECOVERY_ACCOUNT=RECOVER
HS_FDS_RECOVERY_PWD=RECOVER
$ORACLE9I_HOME etworkadmin 下listener.ora內容如下:
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)(PORT = 1521))
)
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = test9)
(ORACLE_HOME = d:oracleora92)
(SID_NAME = test9)
)
(SID_DESC=
(SID_NAME=pubs)
(ORACLE_HOME=d:OracleOra92)
(PROGRAM=tg4msql)
)
(SID_DESC=
(SID_NAME=northwind)
(ORACLE_HOME=d:OracleOra92)
(PROGRAM=tg4msql)
)
)
重啟動這臺做gateway的windows機器上(IP:192.168.0.2)TNSListener服務.
(凡是按此步驟新增可訪問的SQL Server資料庫時,TNSListener服務都要重啟動)
2、ORACLE8I,ORACLE9I的伺服器端配置tnsnames.ora, 新增下面的內容:
pubs =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)(PORT = 1521))
)
(CONNECT_DATA =
(SID = pubs)
)
(HS = pubs)
)
northwind =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)(PORT = 1521))
)
(CONNECT_DATA =
(SID = northwind)
)
(HS = northwind) )
儲存tnsnames.ora後,在命令列下
tnsping pubs
tnsping northwind
出現類似提示,即為成功
Attempting to contact (DESCRIPTION = (ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)
(PORT = 1521))) (CONNECT_DATA = (SID = pubs)) (HS = pubs))
OK(20毫秒)
Attempting to contact (DESCRIPTION = (ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)
(PORT = 1521)))
(CONNECT_DATA = (SID = northwind)) (HS = northwind))OK(20毫秒)
設定資料庫引數global_names=false。
設定global_names=false不要求建立的資料庫連結和目的資料庫的全域性名稱一致。global_names=true則要求, 多少有些不方便。
oracle9i和oracle8i都可以在DBA使用者下用SQL命令改變global_names引數
alter system set global_names=false;
建立公有的資料庫連結:
create public database link pubs
connect to testuser identified by testuser_pwd using 'pubs';
create public database link northwind
connect to testuser identified by testuser_pwd using 'northwind';
(假設SQL Server下pubs和northwind已有足夠許可權的使用者登陸testuser,密碼為testuser_pwd)
訪問SQL Server下資料庫裡的資料:
select * from stores@pubs;
...... ......select *
from region@northwind;
...... ......
3、使用時的注意事項
ORACLE透過訪問SQL Server的資料庫連結時,用select * 的時候欄位名是用雙引號引起來的。
例如:
create table stores as select * from stores@pubs;
select zip from stores;
ERROR 位於第 1 行:
ORA-00904: 無效列名
select "zip" from stores;
zip
-----
98056
92789
96745
98014
90019
89076
已選擇6行
用SQL Navigator或Toad看從SQL Server轉移到ORACLE裡的表的建表語句為:
CREATE TABLE stores
("stor_id" CHAR(4) NOT NULL,
"stor_name" VARCHAR2(40),
"stor_address" VARCHAR2(40),
"city" VARCHAR2(20),
"state" CHAR(2),
"zip" CHAR(5))
PCTFREE 10
PCTUSED 40
INITRANS 1
MAXTRANS 255
TABLESPACE users
STORAGE (
INITIAL 131072
NEXT 131072
PCTINCREASE 0
MINEXTENTS 1
MAXEXTENTS 2147483645
)
/
總結:
WINDOWS下ORACLE9i閘道器伺服器在$ORACLE9I_HOME g4msqladmin目錄下的initsqlserver_databaseid.ora
WINDOWS下ORACLE9i閘道器伺服器listener.ora裡面
(SID_DESC=
(SID_NAME=sqlserver_databaseid)
(ORACLE_HOME=d:OracleOra92)
(PROGRAM=tg4msql)
)
UNIX或WINDOWS下ORACLE8I,ORACLE9I伺服器tnsnames.ora裡面
northwind =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.2)(PORT = 1521))
)
(CONNECT_DATA =
(SID = sqlserver_databaseid)
)
(HS = sqlserver_databaseid)
)
sqlserver_databaseid一致才行.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10617542/viewspace-962841/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 從Oracle訪問SQL Server(GATEWAYS)OracleSQLServerGateway
- SQL Server建立Linked Server訪問OracleSQLServerOracle
- 在Linux下訪問MS SQL Server資料庫(轉)LinuxSQLServer資料庫
- NetScreen裡設定控制訪問
- Oracle Gateways透明閘道器訪問SQL ServerOracleGatewaySQLServer
- SQL Server通過dblink訪問Oracle資料SQLServerOracle
- oracle透過透明閘道器訪問sql serverOracleSQLServer
- SQL Server的安全設定問題解答SQLServer
- SQL Server 2005裡設定自增欄位SQLServer
- 在Oracle 9ias中的pl/sql包的訪問控制(轉)OracleSQL
- ORACLE多個event設定方式Oracle
- Sql Server在.net中的資料訪問輔助類SQLServer
- 在SQL Server 2000中設定OPTION (MAXDOP 1) 效能提高問題SQLServer
- 為多個平臺或平臺下多個賬號設定SSH協議訪問協議
- SQL Server 資料訪問策略:CLRMESQLServer
- PHP 設定多域名允許跨域訪問PHP跨域
- SQL SERVER安全設定攻略SQLServer
- SQL Server管理員帳號鎖定後如何恢復訪問VUSQLServer
- ABAP訪問外部SQL (轉)SQL
- SQL Server 資料訪問策略:即席SQLCUSQLServer
- NFS Server設定(轉)NFSServer
- order by在SQL Server與Oracle中的一個區別SQLServerOracle
- 實戰oracle gateway訪問sql server2000資料庫OracleGatewaySQLServer資料庫
- SQL Server 2005中設定Reporting Services釋出web報表的匿名訪問SQLServerWeb
- SQL Server 函式返回多個值SQLServer函式
- SQL Server定時作業的設定方法SQLServer
- SQL Server Profiler 設定注意事項SQLServer
- Oracle Sequence不設定cache引數的幾個潛在問題Oracle
- SQL SERVER和ORACLE的排序問題SQLServerOracle排序
- Nginx設定訪問伺服器某個目錄Nginx伺服器
- Oracle與SQL Server在企業應用中的比較(轉)OracleSQLServer
- SQL in ORACLE and SQL ServerSQLOracleServer
- postgresql如何設定外界訪問SQL
- Harbor設定https訪問HTTP
- 解析SQL Server中行轉列問題SQLServer
- ORACLE 9i 建立透明閘道器訪問SQL Server 2008OracleSQLServer
- 在Oracle SQL中設定每週的起始日期IOOracleSQL
- tomcat高訪問設定問題Tomcat