Linked Server - Can see tables but not columns - mysql

I am trying to query a linked server, when I expand object explorer in SSMS, I can see all db's on the server and all tables within the respective db's but cannot expand to see the columns. I also cannot run any queries with the following errors:
1 - If I right click on the table name and click script table as - select to - new query window, I get the following error
[LinkedServerName].[singhm]..[testtable] contains no columns that can be selected or the current user does not have permissions on that object.
2 - If I run the an openquery statement as follows:
select *
from openquery(LinkedServerName ,'select * from [singhm]..[testtable]')
I get the following error:
Cannot initialize the data source object of OLE DB provider "MSDASQL"
for linked server "LinkedServerName".
For context purposes, My linked server is an ODBC connection to a MySQL db datasource.
I would be grateful for any advice and/or direction regarding this matter.
Many thanks,
Manpaal Singh

I needed to download and install a different odbc provider. I can now query the linked server using the following syntax.
select top 10 * from openquery(MYSQL,'select * from singhm.testtable')

Related

SSIS - Deployed package SQL Command validation error

I have created a SSIS package in order to transfer datas from ACCESS to SQL SERVER.
Source > SQL Command from "mdb" file joinning two tables
Destination > Flat table in SQL Server
I'm performing the JOIN in the source SQL Command because of the number of records in the ACCESS tables (~500k).
I tried to use SSIS join but it take ages doing the ORDERING before JOIN.
While running package in VS2010, it works great.
But after deploying and executing the package on my SQL Server 2014 the following error occurs.
No column information was returned by the SQL command.
Returned validation status "VS_NEEDSNEWMETADATA"."
I'm pretty sure my SQL command is correct (Working in VS and the preview button in the editor show me records).
I tried to disable ValidateMetadata but the same error still occurs, but at execution this time.
In the SQL Server 2014 I have other packages calling ACCESS data (But without join) and it works properly.
Thanks for your help,
Q.
ValidateMetadata is (generally) a good thing.
This error is being caused by the metadata on your source or destination (it's unclear from your question) being different.
At a guess, at least one of the columns in your SQL2014 database is of a different datatype (or length, or is nullable etc.) - there is a difference either way.

Settting up a SSMS Linked Server to DB2

I have a local SQL Server instance on which I created a Linked Server connection to a DB2 database named "DB2OurDatabase." In creating the Linked Server connection, I specified a UID and PWD that I use in various query tools or applications to query "[SchemaX].[TableX]."
I seemed to have success in creating the Linked Server: A Linked Server node Object by the name of "DB2OurDatabase" was created under the Linked Server node in SSMS and when I expand it, I am able to see the of tables in the database.
When I right mouse click on the [SchemaX].[TableX] table and select
"Script Table as => Select To ==> New Window", a new query window was opened with the text
--[DB2OurDatabase].[DataCenterCityName2_DB2OurDatabase].[SchemaX].[TableX]
contains no columns that can be selected or the current user does not have permissions on that object.
GO
I don't understand how I was able to create a Linked Server that can see the table names in the database but yet apparently seem to encounter what appears to be a lack of rights to query the table even tghough I am using same credentials that I have used in Squirell SQL query tool, for example, to query the table.
In SSMS, I tried to execute this
SELECT *
FROM [DB2OurDatabase].[DataCenterCityName2_DB2OurDatabase].[SchemaX].[TableX]
Error:
Msg 7314, Level 16, State 1, Line 1
The OLE DB provider "IBMDADB2" for linked server "DB2OurDatabase]" does not contain the table ""DataCenterCityName2_DB2OurDatabase"."SchemaX"."TableX"". The table either does not exist or the current user does not have permissions on that table.
I was a little surprised that the fully qualified table name included [DataCenterCityName2_DB2OurDatabase] since I did not specify this when I set up the Linked Server connection, but the name of the DataCenter city was correct so I took this as a further sign that the Linked Server connection was successful.
Nevertheless, I also tried to execute remove this level of the fully qualified table name:
SELECT *
FROM [DB2OurDatabase].[SchemaX].[TableX]
which resulted in this error.
Msg 208, Level 16, State 1, Line 1
Invalid object name 'DB2OurDatabase.[SchemaX].[TableX]'.
What do I need to do to create a DB2 Linked Server that lets me query the tables in the DB2 database? Here's my linked server properties:
I haven't investigate what are probably multiple ways to conenct and query DB2 from Sql Server, but this worked:
SELECT * FROM OPENQUERY(DB2OurDatabase, 'SELECT * FROM SchemaX.TableX')
Obviously, you modified the actual commands by replacing object names, so it's impossible to be sure, but the problem may be caused by your use of quoted identifiers (those square brackets), which essentially makes the object names case-sensitive. DB2 will by default create object (table, schema) names in uppercase, unless they are quoted. create table MySchema.MyTable... (unquoted) on the DB2 side will create the table MYSCHEMA.MYTABLE, and referencing it later from SSMS as [MySchema].[MyTable] (using quoted identifiers) will obviously fail.
These are the 3 steps that bring me to the solution:
Download and install Microsoft OLE DB Provider for DB2 Version 6.0 (this is the latest version but by the time you read this post there might be a new version now)
From the start menu open the Data Access Tool > File > New Data Source and complete all the steps: provide the notorious credentials like Server, Port, Database, User, Password. If unsure contact your DBA. Once completed test the connection and copy the Connection String
Now on SSMS go to Server Object > Linked Servers > New Linked Server and fill up like in picture setting up in the Provider string the string you copied before from the Data Access Tool:
Done, you are good to go now,

Joinning SQL Server table with *.mdb file

I'm trying to joinning SQLServer 2008 R2 tables with msaccess table (*.mdb).
I already tried "OPENDATASOURCE" and "Linked Server", but no one of them is work correctly.
in example, I've got the following message:
OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server
"TestLinkServer" returned message "Cannot open database ''. It may
not be a database that your application recognizes, or the file may be
corrupt.".
the other error message:
OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "MDBTest"
returned message "The Microsoft Jet database engine cannot open the
file '\10.55.56.34\Shared Folder\LBUS.mdb'. It is already opened
exclusively by another user, or you need permission to view its
data.".
and many more :D
can anyone give the working tutorial?
thanks in advance.. :)
The easiest way is to do the join inside ms-access.
Set up a table link in your access database that references the sql-server table you want to join.
Then build a query in access that joins that table with one or more tables in the access database.
If you want to join more than one sql-server table, first create a view in sql-server that combines all the relevant tables. Then set up your table link to reference the view.
If, for some reason, you must do the join inside SQL server, you will have to use a different technique, or use the table link feature to "push" data from the access table to a (previously defined) sql server table. Then, it's just an ordinary join.

Do I have to use OpenQuery to query a MySQL Linked Server from SQL Server?

I'm querying a MySQL linked server from SQL Server.
I can query the linked server using OpenQuery as in the following example.
SELECT * FROM OPENQUERY(MyLinkedServer, 'SELECT * FROM SomeTable')
I have tried querying the linked server using a four-part name as in the following example.
SELECT * FROM MyLinkedServer.MyDatabase.DBO.SomeTable
That returns an error stating that "the provider does not expose the necessary interfaces to use a catalog or schema."
Is there any way to query a linked server without using OpenQuery?
Thanks!
Update: Per Shredder's answer, the correct syntax is as follows.
SELECT * FROM MyLinkedServer...SomeTable
It is possible, but MS recommends that you use the openquery:
This method lets SQL Server send the command directly to the linked
OLAP provider, without trying to parse it.
You can have a look at the examples here under "Linked server examples with four-part names"
Also, I found this:
If you receive these error messages, a table may be missing in the
[Linked DB] schema or you may not have permissions on that table.
I would verify that your mysql db has given access rights to your sql server.

MySQL as Linked Server on SQL Server 2008 - Data Length Mismatch

I am trying to set up a third party MySQL as a Linked Server on SQL Server 2008.
When I try to access the data via a simple OpenQuery below I get an error.
SELECT * FROM OpenQuery(SERVERNAME, 'SELECT * FROM table')
The error message:
OLE DB provider 'MSDASQL' for linked server 'SERVERNAME' returned data that does not match expected data length for column '[MSDASQL].tablename'. The (maximum) expected data length is X, while the returned data length is Y.
NOTE:(where X > Y)
I've tried with another MySQL table that I built myself and it works fine. Therefore I assume the problem might be with the MySQL source.
EDIT: After digging a little deeper into the MySQL data I found several "invalid" dates such as zero dates. These could be a reason, however I have no way to change the data source so I must find a way to convince SQL to ignore it.
I recall something form previous versions of SQL where you could switch to "Lazy Schema Validation" to force SQL not to check this. However this option appears to be gone in 2008.
Any ideas how I could make this work?