Solved

Cannot get column information from ole DB provider for Linked server

Posted on 2014-01-24
8
3,731 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
  • 3
  • 3
  • 2
8 Comments
 
LVL 26

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
 

Author Closing Comment

by:LenTompkins
ID: 39811972
Once I took the database name out of the select, it worked.  Thanks very much.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 26

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 26

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
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.

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now