SQL Server : get access to linked server through linked server - sql-server-2008

I have SQL Server 2008 with linked server, for example Server1. Usually I execute queries like
SELECT *
FROM [Server1,1444].[DBName].[dbo].[Table1]
But this time my target table is stored at different server. This server is linked on Server1 like Server2. So, DBA of Server1 gave me a this query
SELECT *
FROM [Server2].[DB].[dbo].[My_table]
On Server1 this query runs without troubles, but when I try to run it on my own server like:
SELECT *
FROM [Server1,1444].[Server2].[DB].[dbo].[My_table]
it shows me an error message, because I'm trying to query one linked server through other linked server.
My question is: how can I execute my query to that Server2?

So I've found solution
SELECT *
FROM openquery([Server1,1444], 'SELECT* FROM [Server2].[DB].[dbo].[My_table]')

Related

Attempting to retrieve data from linked server - Lost connection to MySQL server at 'waiting for initial communication packet', system error: 10060"

I have an application which connects and stores data on a MySQL database, I need to connect and retrieve this data in a view from another application which uses an SQL Server Database. My attempt to handle this was to create a linked server that connects to the MySQL Server in SQL Server.
That seems to have worked, all connections have passed and if I run the following queries
SELECT * FROM MYSQLLINK...table1` or `SELECT * FROM OPENQUERY(MYSQLLINK, 'SELECT * FROM table1')
I get results.
Problem
The problem is, I want to create a view which joins quite a few reference tables ( I actually have 20 joins but it's joining the same table because it's a big reference table.)
but on execution on the SELECT or CREATE VIEW I get the following error.
OLE DB provider "MSDASQL" for linked server "MYSQLLINK" returned
message "[MySQL][ODBC 5.1 Driver]Lost connection to MySQL server at
'waiting for initial communication packet', system error: 10060".
Msg 7303, Level 16, State 1, Line 4
Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "MYSQLLINK".
Completion time: 2020-01-19T22:00:00.1759949-04:00
I am unsure why this is occurring, would appreciate if any could assist in figuring this out and helping in mitigating this error that will allow my view to be created and queried.
I've noticed if I comment out 85% of the joins the query does not fail. Where would I increase this time out the tome that is mentioned?
I should also mention that the MySQL is on an AWS server while the SQL Server is on my localhost.
I couldn't recreate the failure test case on my local-end, but what you mentioned directs us to following pointers:
Your linked server connection is getting timeout (probably)
Potential reason for timeout could be the high response time of query (view which joins quite a few reference tables)
What about changing the approach:
Can you create the view on MySQL rather than on SQL Server?
Is materialization of the result of the view is an option?
Or alternatively, what about writing a stored procedure on SQL Server-end and sequentially join your tables one-at-a-time (or as-many-reasonable-at-a-time) with use of temporary tables to store intermediate results?

SQL Linked Server to MySQL database does not work because of missing or´incorrect schema

I want to establish a linked Server Connection from my Office SQL-Server to a web hosted MySQL-database.
Before that I tried to Setup a Connection to a copy of this MySQL-database on localhost.
I created a linked Server in Management Studio pointing to my MySQL-database
it Looks like this:
Testing the Connection was OK, I can see all databases in MySQL.
But when I do a SELECT on one of the tables in a certain database I get an error 7312.
When I generate a select script by SSMS it Comes up with
Select * from [MYSQL_local_ASV].[asvdb]..[descriptions]
not showing any Schema (..) althoug I can connect to the Server.
If I check the table's Schema in MySQL Workbench it Shows the Schema name 'asvdb'. For me it Looks like there is a Schema 'asvdb' with a database called 'asvdb'.
I checked also with [MYSQL_local_ASV].[asvdb].[asvdb].[descriptions].
Same error.
Maybe someone can explain me whats wrong with this and have some example of how to connect to a table in a linked Server.
So, the Problem is, I assumed that database and Schema in mysql are the same, but what does SQL-Server Need to complete the Connection string properly?
If I cannot establish this local connectin I will never get it to a web hosted MySQL-database, so please help me!
Thanks
Michael
use this format for select query
Execute ('select * from tablename')at LinkedServername

How to setup/map remote mysql db in local phpmyadmin

I am working on a remote development server. I have the mysql host name, db name, user name , password of that remote server. I want to setup/replicate/map that dev server mysql in my local phpmyadmin, so that I can access the remote server db locally(for ex :- /mylocalip/remote-server-db).
Thus I don't have to do ssh connection and open the mysql in terminal. How can we do this in phpmyadmin/config.inc.php.
Let me explain again through an example. Lets say the remote server db is accessible through 213.81.203.130/phpmyadmin. I want to access that db from my local ip through an alias name by creating a mapping i.e 192.168.10.140/remote-db. Basically this can be done by adding some sort of code in phpmyadmin/config.inc.php or config.db.php. But how to do it I am not sure.
If you want to avoid using terminal, why not try MySQL Workbench to connect to the database?
UPDATE
In light of all the views to this question, I am adding a solution that more accurately matches the question. Please see this link, I believe it will be helpful. It involves editing the phpmyadmin config.inc.php file to add additional servers. This is how you can keep your localhost connection, and add any remote db connections. Simply select the server from the drop down at the login screen to phpmyadmin.
There are 3 methods to set this up
METHOD #1 : MySQL Replication
Setup MySQL Replication where the Slave has this option
replicate_do_table=mydb.mytable
Then, any DML (INSERT, UPDATE, DELETE) or DDL (ALTER TABLE) you execute will go immediately to serverB. This makes Method #1 is the fastest and most granular approach.
METHOD #2 : Copying the table to the other server
Rather than rehash, Here is an earlier post, Mr. RolandoMySQLDBA did May 31, 2011 for this method : [How do you copy a table from MySqlServer_A to MySqlServer_B?][1]
METHOD #3 : FEDERATED Table (MyISAM Only)
Suppose mytable on serverA looks like this
CREATE TABLE mydb.mytable ( ... ) ENGINE=MyISAM;
You can a mapping of the target table in serverB by running this on serverA like this
CREATE TABLE mydb.mytable_remote LIKE mytable; ALTER TABLE
mydb.mytable_remote ENGINE=FEDERATED
CONNECTION='mysql://username:password#serverB/mydb/mytable';

Unable to execute SQL queries on remote server

I am connecting to a Microsoft SQL Server 2008 instance (running on my local host) using the jtds driver and trying to execute basic query as follows.
select * from Test
However I get an SQLException as -
java.sql.SQLException: Table not found in statement [select * from Test]
Interestingly I can log in to the server and manually execute the same query without any problems.
I have also tried the following options
select * from <DB name>.dbo.Test
select * from dbo.Test
select * from [Test]
The user I am logging in has db admin rights for all the databases.
Any help will be much appreciated!
Thanks
connect to the db in your connection to the same database in which the table is.

Using SQL Server specific code in Access linked to SQL Server database

I have an access file that is linked (through an ODBC connection) to a SQL Server 2008 database. I am trying to write some reports against this database. However, Access chokes when I write the select query of the report with SQL syntax specific to SQL Server that doesn't exist in access. Shouldn't this work, since it's the SQL Server engine running the queries and just sending the data back to Access to display? Is there any way to get this to work?
Need this to work on any combination of Access 2007 and 2010, and SQL Server 2005 and 2008.
Edit
Note: I cannot create a SQL Server stored procedure or function, or otherwise modify the original (SQL Server) schema in any way.
Found the answer: I need to use a "pass-through query".