Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Cannot get column information from ole DB provider for Linked server

Posted on 2014-01-24
8
Medium Priority
?
5,061 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 1000 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 1000 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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 

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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

598 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