Dynamic SQL Error -104 from Linked Firebird Database - sql-server

I have a SQL Server database and a Firebird database as a linked server. I'm trying to select a table in the linked server, but I get the following error:
OLE DB provider "MSDASQL" for linked server "FIREBIRD" returned message "[ODBC Firebird Driver][Firebird]Dynamic SQL Error
SQL error code = -104
Token unknown - line 1, column 22
.".
Msg 7306, Level 16, State 2, Line 4
Cannot open the table ""de_ib"."ROHSTOFF"" from OLE DB provider "MSDASQL" for linked server "FIREBIRD".
I have synonyms for the linked tables set up in my SQL database. The following three statements all return this error:
SELECT * FROM ROHSTOFF
SELECT * FROM [dbo].[ROHSTOFF]
SELECT * FROM [FIREBIRD].[de_ib]..[ROHSTOFF]
But the following returns the data as expected:
SELECT * FROM OPENQUERY(FIREBIRD, 'SELECT * FROM ROHSTOFF')
If I right-click a linked table and select Script Table as > INSERT To > New Query Editor Window, the following appears in the query editor:
-- [FIREBIRD].[de_ib]..[ROHSTOFF] contains no columns that can be selected or the current user does not have permissions on that object.
I'm logged in with credentials that match the owner of the Firebird database.
Why am I getting this error and how can I select data from my linked server without using OPENQUERY? I have a legacy application that selects from the Firebird database, but I need it to select seamlessly from the synonyms instead.

Related

Move Image column from OracleDB top SQL Server

I have access to an Oracle database and I need to bring its data into SQL Server. The table has a simple structure and I can't change anything on the Oracle side.
I created a linked server inside SQL Server but I can't select the table because of this error :
The OLE DB provider "OraOLEDB.Oracle" for linked server supplied inconsistent metadata for a column. The column (compile-time ordinal 1) of object was reported to have a "DBCOLUMNFLAGS_ISFIXEDLENGTH" of 16 at compile time and 0 at run time
The OLE DB provider "OraOLEDB.Oracle" for linked server supplied inconsistent metadata for a column. The column (compile-time ordinal 1) of object was reported to have a "DBCOLUMNFLAGS_ISFIXEDLENGTH" of 16 at compile time and 0 at run time
I checked and it seems to be a general problem and Oracle suggested using OPENQUERY to get data from these tables.
When I use OPENQUERY the IMAGE ( 'BFILE' ) column is null but I can see in SQL Developer that it is not null.
When I use SSIS, I get this error:
ADO NET Source [33]] Error: The error "ORA-00972: identifier is too long occurred while processing "ADO NET Source.Outputs[ADO NET Source Output].Columns[IMAGE]
Any ideas on how to move a table with an IMAGE (BFILE) column from Oracle database to SQL Server?

SQL Server select from linked server throw error if user has "deny view definition"

I have users with datareader permission on my sql, the problem is that i noticed that the users are doing "fishing" query a lot (they don't know what exactly should be querying to get what thy need).
This is a production SQL and we started to have deadlock because of those users.
Trying to don't break their process i applied "deny view definition to [user]" so they cannot see the list of tables, view, stored procedure, so no more "fishing"
This was a great solution, it works perfect if you connect directly to the SQL Server, you can run queries (select) but you cannot see the list of tables.
However many users are using those account to connect to our SQL using linked server, and when the run a query using the linked server they are getting error:
SELECT TOP 100 *
FROM [SERVERSQL].[DATABASE].dbo.[TABLE]
Msg 7314, Level 16, State 1, Line 1
The OLE DB provider "SQLNCLI11" for linked server "SERVERSQL" does not contain the table ""[DATABASE]"."dbo"."[TABLE]"". The table either does not exist or the current user does not have permissions on that table.
Using SQL Server version 2014 (v12.0.2000.8) and 2016 (v13.0.5492.2).
What is the correct way to hide tables, view, stored procedures, etc but allow select and make it work on linked server?
Thanks
Linked server from one SQL Server to Another:
Linked server name is: PLWNSAVSQL02D which is SQL Server
This sql to linked server works:
select count(*) from [PLWNSAVSQL02D].[SFI_WMS].dbo.[TCOMPANYPALLETMESSAGES];

Querying an Oracle database from SQL Server

I have an Oracle 11g XE database that I would like to transfer into SQL Server Express 2005.
At first I thought I'd just generate the tables in Oracle as SQL, manipulate the data formats, and run the query in SQL Server. This worked for small tables, but I have several tables with a few hundred thousands rows and some with millions of rows, so this solution won't work.
I then created a TNS file with the following content:
OracleTnsName =
(
DESCRIPTION=
(
ADDRESS = (PROTOCOL=TCP)(HOST=localhost)(PORT=1521)
)
(
CONNECT_DATA = (SERVICE_NAME=XE)
)
)
I followed instructions I found elsewhere on how to generate the ODBC connection, and the 'test connection' was successful.
I then ran these commands to create a Linked Server in MS SQL:
EXEC sp_addlinkedserver
#server = 'OracleLinkServer'
,#srvproduct = 'OracleTnsName'
,#provider = 'MSDASQL'
,#datasrc = 'OracleTnsName'
EXEC sp_addlinkedsrvlogin
#rmtsrvname = 'OracleLinkServer'
,#useself = 'False'
,#locallogin = NULL
,#rmtuser = 'user'
,#rmtpassword = 'password'
Now I'm trying to query a table in the Oracle database from SQL Server using openquery:
select * from openquery(OracleLinkServer, 'select * from oracleTable')
But get an error:
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "MSDASQL" for
linked server "OracleLinkServer" reported an error. The provider did
not give any information about the error.
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider
"MSDASQL" for linked server "OracleLinkServer".
When I check the properties of the Linked Server, and just click the OK, I get this error:
TITLE: Microsoft SQL Server Management Studio Express
"The linked server has been updated but failed a connection test. Do you want to edit the linked server properties?"
ADDITIONAL INFORMATION:
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.Express.ConnectionInfo)
The OLE DB provider "MSDASQL" for linked server "OracleLinkServer" reported an error. The provider did not give any information about the error.
Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "OracleLinkServer". (Microsoft SQL Server, Error: 7399)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=09.00.5000&EvtSrc=MSSQLServer&EvtID=7399&LinkId=20476
BUTTONS:
&Yes
&No
Please help!
Thanks
If you have successfully added your linked server, you no longer need OPENQUERY. You can just include the linked server name as the first part of the qualified name like so:
SELECT * FROM OracleLinkServer.database.schema.table
Not sure which parts you need, but the dots are key. Try this first:
SELECT * FROM OracleLinkServer...oracleTable
select *
from [server]..[xxx].[yyyyy]
It works for me.
Change
,#provider = 'MSDASQL'
with
,#provider = 'MSDAORA'

In SQL server, how can I query an Oracle Timestamp column over a Linked server connection?

The query I have made in oracle does not work with linked server with sql server 2008.
The OLE DB provider "MSDAORA" for linked server "ORACLE" supplied
invalid metadata for column "DATETIME_INS". The data type is not
supported.
The query:
select * from ORACLE..U_GERAN.CELLSTATS4
What are the modification that must be done to execute the query.
Try,
SELECT *
FROM OPENQUERY(ORACLE, 'select cast(DATETIME_INS as DATE) from U_GERAN.CELLSTATS4')
You can add the other columns to the query once that column works.

Unable to Query a View from a Linked SQL Server

In SQL Server Management Studio, I have linked a SQL Server, sql02 to my local server as such:
sp_addlinkedserver 'sql02'
GO
I can query tables from this server:
SELECT * FROM SQL02.SomeDatabase.dbo.SomeTable
However, when I try to query a view, as in
SELECT * FROM SQL02.SomeDatabase.dbo.SomeView
I get the following error message:
Msg 7314, Level 16, State 1, Line 1
The OLE DB provider "SQLNCLI10" for linked server "SQL02" does not contain the
table ""SomeDatabase"."dbo"."SomeView"". The table either does not exist or the
current user does not have permissions on that table.
Agreed that SomeView does not exist as a table. What am I doing wrong?
Potentially relevant facts:
Local version of SQL Server is 10.50.1617
Version of linked server is 8.0.2282
I can SELECT from all the underlying tables in the view
Looks like a permission issue, have you checked the permissions on the view? There's nothing wrong with your query.
Also, have you checked what table does that view query on? Check the table permissions as well.
As a tip: Try to run the view on a specific user and if that's successful try to link the server using that specific user.

Resources