【问题标题】:How to connect to Oracle by ODBC如何通过 ODBC 连接到 Oracle
【发布时间】:2019-08-23 12:22:48
【问题描述】:

我必须从 Microsoft SQL Server Management Studio 连接到 Oracle 数据库。 客户说我可以通过 ODBC 访问。 我知道 ip、端口、用户名、密码和 SID。 我应该添加链接服务器吗?或者我可以只在查询中这样做吗? 之前没用过其他数据库所以不知道怎么连接。

【问题讨论】:

    标签: sql-server oracle odbc


    【解决方案1】:
                MSSQL to Oracle
    
    
    1.    Install Oracle binaries in windows machine (select software only option while installation. Do not select database)
    
    
    2.    In windows machine
    a.    Check if the listener exists
    b.    If listener exists , use that listener (here listener is 1521 , use the listener in given listener)
    c.    If not , open Net Configuration Assistant and follow steps to create listener.
    d.    Check the status of listener. Open command prompt and type lsnrctl status. If the listener is not active type lsnctrl start . the listener should start.
    e.    Open file listener.ora (E:\Oracle_file\product\11.2.0\dbhome_1\NETWORK\ADMIN)
    f.    In listener.ora : write following contents:
    # listener.ora Network Configuration File: E:\Oracle_file\product\11.2.0\dbhome_1\network\admin\listener.ora
    # Generated by Oracle configuration tools.
    LISTENER=  (DESCRIPTION_LIST =    (DESCRIPTION =
          (ADDRESS = (PROTOCOL = TCP)(HOST = ip)(PORT = 1521))
          (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))  )  )
    SID_LIST_LISTENER =  (SID_LIST =    (SID_DESC =      (SID_NAME = dg4odbc)      (ORACLE_HOME = E:\Oracle_file\product\11.2.0\dbhome_1)
          (PROGRAM = dg4odbc)      (ENVS = "EXTPROC_DLLS=ONLY:E:\Oracle_file\product\11.2.0\dbhome_1\bin\oraclr11.dll")    )  )
    ADR_BASE_MSSQL = E:\Oracle_file
    g.    Edit the locations as per your installation folder
    h.    Save the file listener.ora
    i.    Open tnsnames.ora (E:\Oracle_file\product\11.2.0\dbhome_1\NETWORK\ADMIN)
    j.    Write following content in tnsnames.ora
    # tnsnames.ora Network Configuration File: E:\Oracle_file\product\11.2.0\dbhome_1\network\admin\tnsnames.ora
    # Generated by Oracle configuration tools.
    
    ORACLE =
      (DESCRIPTION =
        (ADDRESS = (PROTOCOL = TCP)(HOST = oracle)(PORT = 1521))
        (CONNECT_DATA =
          (SERVER = DEDICATED)
          (SERVICE_NAME = oracle)
        )
      )
    
    MSSQL =
      (DESCRIPTION =
        (ADDRESS = (PROTOCOL = tcp)(HOST = ip)(PORT = 1521))
        (CONNECT_DATA =
          (SID = dg4odbc)
        )
        (HS = OK)
      )
    
    ORACLR_CONNECTION_DATA =
      (DESCRIPTION =
        (ADDRESS_LIST =
          (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
        )
        (CONNECT_DATA =
          (SID = CLRExtProc)
          (PRESENTATION = RO)
        )
      )
    
    k.    Open administrative tools
    l.    Open ODBC Data Sources (64-bit)
    m.    In System DSN , 
    i.    add a data source in sql native client
    ii.    write the name as the listener name (here LISTENER)
    iii.    point the server to the sql server where you want to access the location
    iv.    In connection point , write the username and password , ie connect in sql server authentication mode
    v.    Test the connection 
    vi.    Close the wizard
    n.    On Windows machine where we installed SQL Server navigate to
    ORACLE_HOME\hs\admin and edit initdg4odbc.ora and save as initdg4dg4odbc.ora and both the files should have the following entries:
    
    Location: ORACLE_HOME\HS\ADMIN
    FileName: initdg4odbc.ora and initdg4dg4odbc.ora
    
    Insert The Following
    # This is a sample agent init file that contains the HS parameters that are
    # needed for the Database Gateway for ODBC
    #
    # HS init parameters
    #
    
    HS_FDS_CONNECT_INFO = <Listener_Name>
    
    HS_FDS_TRACE_LEVEL = off
    
    #
    # Environment variables required for the non-Oracle system
    #
    #set <envvar>=<value>
    
    Where,
    <Listener_Name> should be as per entered in the file listener.ora
    
    
    3.    In linux machine
    a.    Locate tnsnames.ora 
    (/u01/app/oracle/product/11.2.0/db_1/network/admin/) 
    b.    Add following in listener.ora
    SID_LIST_LISTENER =
      (SID_LIST =
        (SID_DESC =
          (GLOBAL_DBNAME = kvlali)
          (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
          (SID_NAME = kvlali)    )  )
    LISTENER =
      (DESCRIPTION_LIST =
        (DESCRIPTION =
          (ADDRESS = (PROTOCOL = TCP)(HOST = kvlali.d2hs.com)(PORT = 1522))
          (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
        )  )ADR_BASE_LISTENER = /u01/app/oracleSave the content
    c.    Save the file
    d.    Start the listener by : lsnrctl start
    e.    If listener is started successfully , the connection has been done
    
    4.    Now go to sql server management studio
    a.    Connect to the instance from where you want to create linked server
    b.    Create a linked server as follows:
    •    Connect to the instance to which the listener connection was created
    •    Go to server objects->linked servers->providers
    •    Right click on providers
    •    Enable allow in process
    •    Go to server objects->linked servers
    •    Right click on linked server and click on ‘New Linked Server’
    •    ‘New Linked Server wizard’ is opened
    Linked server: name of linked server via which you like to access the remote oracle server
    Server type:Other data source
    Provider: Oracle Provider for Ole DB
    Product name:Listener name
    Data Source: Listener name
    In sercurity tab: add login users
    Select be made using the security contest: enter remote username and password(of oracle connection)
    In server options: set Data Access, RPC,RPC out, Use Remote Collation and Enable Promotion of Distributed Transaction to ‘True’
            OR
    Execute following query by changing the required parameters
    EXEC master.dbo.sp_addlinkedserver @server = N'KVLALI', @srvproduct=N'kvlali', @provider=N'OraOLEDB.Oracle', @datasrc=N'kvlali'
    EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'KVLALI',@useself=N'False',@locallogin=NULL,@rmtuser=N'utility',@rmtpassword='########'
    EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'KVLALI',@useself=N'False',@locallogin=N'D2HS\Administrator',@rmtuser=N'utility',@rmtpassword='########'
    EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'KVLALI',@useself=N'False',@locallogin=N'D2HS\i82355',@rmtuser=N'utility',@rmtpassword='########'
    EXEC master.dbo.sp_addlinkedsrvlogin    @rmtsrvname=N'KVLALI',@useself=N'False',@locallogin=N'sa',@rmtuser=N'utility',@rmtpassword='########'
    
    EXEC master.dbo.sp_serveroption @server=N'KVLALI', @optname=N'collation compatible', @optvalue=N'false'
    EXEC master.dbo.sp_serveroption @server=N'KVLALI', @optname=N'data access', @optvalue=N'true'
    EXEC master.dbo.sp_serveroption @server=N'KVLALI', @optname=N'dist', @optvalue=N'false'
    EXEC master.dbo.sp_serveroption @server=N'KVLALI', @optname=N'pub', @optvalue=N'false'
    EXEC master.dbo.sp_serveroption @server=N'KVLALI', @optname=N'rpc', @optvalue=N'true'
    EXEC master.dbo.sp_serveroption @server=N'KVLALI', @optname=N'rpc out', @optvalue=N'true'
    EXEC master.dbo.sp_serveroption @server=N'KVLALI', @optname=N'sub', @optvalue=N'false'
    EXEC master.dbo.sp_serveroption @server=N'KVLALI', @optname=N'connect timeout', @optvalue=N'0'
    EXEC master.dbo.sp_serveroption @server=N'KVLALI', @optname=N'collation name', @optvalue=null
    EXEC master.dbo.sp_serveroption @server=N'KVLALI', @optname=N'lazy schema validation', @optvalue=N'false'
    EXEC master.dbo.sp_serveroption @server=N'KVLALI', @optname=N'query timeout', @optvalue=N'0'
    EXEC master.dbo.sp_serveroption @server=N'KVLALI', @optname=N'use remote collation', @optvalue=N'true'
    EXEC master.dbo.sp_serveroption @server=N'KVLALI', @optname=N'remote proc transaction promotion', @optvalue=N'true'
    
    
    
    Where: @server, @rmtsrvname = server where you want to create link
        @locallogin=the login user of sql server
        @rmtuser=username of oracle user login
        @rmtpassword=password of given user login
    
    c.    In providers for linked server , right click in ‘OraOLEDB.Oracle’
    And enable ‘Allow inprocess’
    d.    Test the linked server by right click on test connection
    e.    Execute query as:
    select * from openquery (kvlali,'select * from dbua_audit_report')
    
    
    Enjoy!!
    

    【讨论】:

    • 如何检查监听器是否存在?我无权访问 Oralce DB 服务器。我有 ip 和端口,我有一个 ping 响应。
    • 您需要联系甲骨文方面的相应人员
    • 此人说他通过 ODBC 提供了基础。他给了我 IP、端口、登录名、密码和数据库名称。这还不够连接?
    • 然后在oracle端跳过创建listner,继续另一端
    【解决方案2】:

    我解决了问题:) 只需从 Oracle 下载软件包,其中包含 'Oracle Provider for OLE DB xxxxxx' 对于 ssms x32 或 x64 的相应版本 以管理员身份打开 cmd 并输入 regsvr32 /i 。 在providers中会显示oraOLEDB.Oracle并通过选择这个provider来创建一个Linked Server,在Data Source::/+可能在安全登录名和密码中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-28
      • 1970-01-01
      • 1970-01-01
      • 2018-10-19
      相关资源
      最近更新 更多