SELECT * FROM MySQL Linked Server using SQL Server without OpenQuery

删除回忆录丶 提交于 2019-12-20 10:34:22

问题


I am trying to query a MySQL linked server using SQL Server.

The below query runs just fine.

SELECT * FROM OPENQUERY([Linked_Server], 'SELECT * FROM Table_Name')

Is it possible to run the same query without using the OpenQuery call?


回答1:


Found the answer here. Now I can the three dot notation query. Thanks

http://www.sparkalyn.com/2008/12/invalid-schema-error/

Go to the provider options screenIn SQL Server 2005 you can see the list of providers in a folder above the linked server (assuming you have appropriate permissions). Right click on MSDASQL and go to properties. In SQL Server 2000, the provider options button is in the dialog box where you create the linked server. Check the box that says “level zero only”




回答2:


you can use the statement below

select * from [linkedServerName]...[databaseName.TableName]

but before executing the code above ,, you have to do some changes ..

in the SQL Server Management Studio , go to "linked servers" Folder , open Providers Folder , find MSDASQL and gets it's property then check "Level Zero Only" press Ok ... then execute above query and Enjoy it !!!




回答3:


Try like this:

SELECT * FROM [Linked_Server]...[db_name.table_name]

Working properly, however there are the problems of converting data types. Safer and more reliable to use is OPEQUERY.

SELECT * FROM OPENQUERY([Linked_Server], 'SELECT * FROM db_name.table_name')



回答4:


You should be able to simply query the linked server directly.

select * from mylinkedserver.database.schema.mytable

EDIT:

Try with the three dot notation as noted in this post: http://www.ideaexcursion.com/2009/02/25/howto-setup-sql-server-linked-server-to-mysql/

SELECT * FROM MYSQLAPP...tables

Msg 7399, Level 16, State 1, Line 1 The OLE DB provider "MSDASQL" for linked server "MySQLApp" reported an error. The provider did not give any information about the error. Msg 7312, Level 16, State 1, Line 1 Invalid use of schema or catalog for OLE DB provider "MSDASQL" for linked server "MySQLApp". A four-part name was supplied, but the provider does not expose the necessary interfaces to use a catalog or schema.

This “four-part name” error is due to a limitation in the MySQL ODBC driver. You cannot switch catalogs/schemas using dotted notation. Instead, you will have to register another DSN and Linked Server for the different catalogs you want to access. Be sure and follow the three-dot notation noted in the example query.




回答5:


There is an important point for using this:

SELECT * FROM [Linked_Server]...[db_name.table_name]

You must go on

Linked Server -> provider-> MSDASQL:

and make sure these three options have been checked

  • Dynamic Parameter
  • Level zero only
  • Allow inprocess

https://www.sqlteam.com/forums/topic.asp?TOPIC_ID=153024



来源:https://stackoverflow.com/questions/31968343/select-from-mysql-linked-server-using-sql-server-without-openquery

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