Unable to execute SQL queries on remote server - sql-server-2008

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.

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 Server : get access to linked server through linked server

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]')

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

Insert error using Linked Server MySQL

I have created a linked server using ODBC driver with following provider string
DRIVER={MySQL ODBC 5.1 Driver};SERVER=HOST;USER=uid;PASSWORD=pw;OPTION=3
My linked server is named MYSQL. If i do Select and UPDATE in that way it works right
SELECT * FROM OPENQUERY(MYSQL,'SELECT * FROM DatabaseName.Table')
UPDATE OPENQUERY(MYSQL, 'SELECT * FROM DatabaseName.Table where test=0') SET test=1
when i try to perform an insert with following syntax
INSERT OPENQUERY(MYSQL,'SELECT Column1, Column2, Column3 from DatabaseName.Table WHERE 1=0') VALUES (10,20,30)
i have this following error
The OLE DB provider "MSDASQL" for linked server "MYSQL" could not INSERT INTO table "[MSDASQL]". Commands out of sync; you can't run this command now.
I think you've got the same problem as this thread on another forum. From the answer that seems to have solved the problem for people there, it looks like your missing the database name from your provider string. Try adding DATABASE=mydb; to your provider string.
Here is the original answer:
Apparently if you try to create the linked server using studio and the
various menus, a small detail is not saved in the connection string,
which is the database!
EXEC master.dbo.sp_addlinkedserver #server='MYSQL', #srvproduct='MySQL',
#provider='MSDASQL', #provstr='DRIVER={MySQL ODBC 5.1
Driver};SERVER=HOST;Port=3306;USER=uid;PASSWORD=pw;OPTION=3;DATABASE=mydb;
the bug in the odbc driver seems to affect only the insert statement
and has been around since 2008... i would have hoped that mysql fixed
it by now...
after you create the linked server using the procedure as above, the
insert works as well as all the rest!
I just experienced the same problem and managed to solve it by deactivating Force use of forward-only cursor and Don't cache results for forward-only cursor for my ODBC connection.
I don't know for sure if both options need to be disabled. I got the hint from here
I linked SQL Server 2012 to MySQL v5.1 via MySQL ODBC/Connector v5.1.11, 64-bit. My link data source is configured to use a system ODBC DSN which already had the MySQL database specified (this is in relation to the previous answers) and yet I still got the error before deactivating those cursors options (by default they are not enabled for new data sources, I was the one who enabled them at some point).

SAS ODBC Connection Error

I am trying to use SAS v9.0 to connect to a MySQL database on a Windows 7 machine. Below is the code I am using.
proc sql;
connect to odbc(datasrc=localhost user= root password=password);
create table tmp as
select *
from connection to odbc
(
select * from mysql.time_zone
)
;
quit;
This is giving me following error.
ERROR: CLI error trying to establish connection: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
I am using the MySQL ODBC 5.1 Driver.
Looks like you haven't set your ODBC data source in windows. Go to start->control panel->system and security->administration->ODBC data sources. Select "add", provide all information asked. Then you should provided ODBC data source name when you submit your proc sql datasrc option.