Solved

Cannot get column information from ole DB provider for Linked server

Posted on 2014-01-24
8
4,464 Views
Last Modified: 2014-01-31
I am trying to select data using SQLServer 2008 from MYSQL on another server.  I created a linked server and the test connection is successful, but when I run the following statement, I get an error.
DECLARE @variable VARCHAR(20)
DECLARE @sqlQuery VARCHAR(8000)
DECLARE @finalQuery VARCHAR(8000)


SET @sqlQuery = 'SELECT PageID FROM wcny_Prod.dbo.[clubUsage] '
SET @finalQuery = 'SELECT * FROM OPENQUERY(wcny_Prod,' + '''' + @sqlQuery + '''' + ')'

EXEC(@finalQuery)

OLE DB provider "MSDASQL" for linked server "wcny_Prod" returned message "[MySQL][ODBC 5.1 Driver][mysqld-5.5.28-log]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.[clubUsage]' at line 1".
Msg 7350, Level 16, State 2, Line 1
Cannot get the column information from OLE DB provider "MSDASQL" for linked server "wcny_Prod".

I have also run the query where I didn't add the database name and schema and received the same results.

I also ran the following select to obtain schema information and it works, but no table information is returned.
EXEC ('SELECT  TABLE_SCHEMA,
        TABLE_NAME,
        COLUMN_NAME
FROM    INFORMATION_SCHEMA.COLUMNS
WHERE   TABLE_NAME = ''[clubUsage]''
        AND TABLE_SCHEMA = ''SchemaName'' ;') AT [wcny_Prod] ;

What kind of additional permissions does the user name need that was used to create the ODBC connection?  I gather this is a connection problem.  Any input would be greatly appreciated.
0
Comment
Question by:LenTompkins
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 27

Accepted Solution

by:
Zberteoc earned 250 total points
ID: 39808146
Don't forget that you are connected to a MySql server so you there is no dbo schema there and you should not use [ ] to wrap objects. You should use:

SELECT PageID FROM clubUsage

Basically whatever query you put in the @sqlQuery variable is executed on the MySql server so it should follow the MySql syntax, which is slightly different than SQL server.
0
 
LVL 40

Assisted Solution

by:Vadim Rapp
Vadim Rapp earned 250 total points
ID: 39808231
Make it simple:

SELECT PageID FROM wcny_Prod...clubUsage

No need in openquery and in exec.
0
 

Author Comment

by:LenTompkins
ID: 39809443
I will try these ideas on Monday when I get back into the office.
0
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 

Author Closing Comment

by:LenTompkins
ID: 39811972
Once I took the database name out of the select, it worked.  Thanks very much.
0
 
LVL 27

Expert Comment

by:Zberteoc
ID: 39812207
Is no big deal but you should not give points to an answer that practically repeated an earlier one.
0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 39812263
> answer that practically repeated an earlier one

It seems a little clarification is in order.

Assuming Zberteoc meant my comment, not only it did not "practically repeat" his, it has nothing in common with it.

When you use openquery, the 2nd parameter gets passed to the remote database server as is. There it gets interpreted by that server, in this case Mysql. This means that you have to write the query using the syntax of the remote server rather than SQL Server - in this case, the syntax of mysql, which is different from SQL Server.

When you use form select * from server.database.owner. table, which is what I suggested, you write the query in SQL Server syntax. The translation to the syntax of the remote database server is then performed by the ODBC driver, so you don't even have to be familiar with it.
0
 
LVL 27

Expert Comment

by:Zberteoc
ID: 39812350
However that was not the issue and your explanation only comes after the points awarded.. Beside that using the OPENROWSET makes it more efficient because the query is executed at the source, results can be filtered so that you only get back what you need, not to mention the advantage of index usage at the source.

Regardless, the question had some code that the asker used and needed and my answer was in regards to that. Even if your answer is correct it came later and did not give any extra information so at least the points should had been distributed differently.
0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 39812438
>  your explanation only comes after the points awarded

which perhaps means that the question author recognized the value of it, and in fact did not even need the explanation. The clarification was for you, in case you did not realize it.

> using the OPENROWSET makes it more efficient because the query is executed at the source

The query, certainly, is executed at the source anyway. Indeed, having it translated into the native syntax saves 1-2 ms of processor time required for the ODBC driver to do the same.

> Even if your answer is correct it came later

The points usually depend on the perceived (by the question author) value of the comment, rather than the speed.

> and did not give any extra information
perhaps the author had little different view...

> so at least the points should had been distributed differently.
This is up to the author. I actually requested attention, maybe we will hear from the mod, if it's really a good idea to put a pressure on the author not to award points to other experts.
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question