Querying an Oracle database from SQL Server

我怕爱的太早我们不能终老 提交于 2019-12-19 03:20:35

问题


I have an Oracle 11g XE database that I would like to transfer into SQL Server Express 2005.

At first I thought I'd just generate the tables in Oracle as SQL, manipulate the data formats, and run the query in SQL Server. This worked for small tables, but I have several tables with a few hundred thousands rows and some with millions of rows, so this solution won't work.

I then created a TNS file with the following content:

OracleTnsName = 
(
  DESCRIPTION=
  (
    ADDRESS = (PROTOCOL=TCP)(HOST=localhost)(PORT=1521)
  )
  (
    CONNECT_DATA = (SERVICE_NAME=XE)
  )
)

I followed instructions I found elsewhere on how to generate the ODBC connection, and the 'test connection' was successful.

I then ran these commands to create a Linked Server in MS SQL:

EXEC sp_addlinkedserver 
     @server            = 'OracleLinkServer'
    ,@srvproduct        = 'OracleTnsName'
    ,@provider          = 'MSDASQL'
    ,@datasrc           = 'OracleTnsName'

EXEC sp_addlinkedsrvlogin 
     @rmtsrvname        = 'OracleLinkServer'
    ,@useself           = 'False'
    ,@locallogin        = NULL
    ,@rmtuser           = 'user'
    ,@rmtpassword       = 'password'

Now I'm trying to query a table in the Oracle database from SQL Server using openquery:

select * from openquery(OracleLinkServer, 'select * from oracleTable')

But get an error:

Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "MSDASQL" for linked server "OracleLinkServer" reported an error. The provider did not give any information about the error.
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "OracleLinkServer".

When I check the properties of the Linked Server, and just click the OK, I get this error:

TITLE: Microsoft SQL Server Management Studio Express

"The linked server has been updated but failed a connection test. Do you want to edit the linked server properties?"


ADDITIONAL INFORMATION:

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.Express.ConnectionInfo)


The OLE DB provider "MSDASQL" for linked server "OracleLinkServer" reported an error. The provider did not give any information about the error. Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "OracleLinkServer". (Microsoft SQL Server, Error: 7399)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=09.00.5000&EvtSrc=MSSQLServer&EvtID=7399&LinkId=20476


BUTTONS:

&Yes

&No

Please help!

Thanks


回答1:


If you have successfully added your linked server, you no longer need OPENQUERY. You can just include the linked server name as the first part of the qualified name like so:

SELECT * FROM OracleLinkServer.database.schema.table

Not sure which parts you need, but the dots are key. Try this first:

SELECT * FROM OracleLinkServer...oracleTable



回答2:


select * 
from [server]..[xxx].[yyyyy] 

It works for me.




回答3:


Change

,@provider = 'MSDASQL'

with

,@provider = 'MSDAORA'


来源:https://stackoverflow.com/questions/11309762/querying-an-oracle-database-from-sql-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!