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

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];

Related

How to add Sybase SQL Anywhere DB as linked server to MS SQL Server properly

I used the Microsoft OLE DB Provider for SQL Anywhere to create a linked server, it shows remote databases and tables, I can read data, but writing data seems to work only using OPENQUERY() and when doing the connection_authentication using EXEC ... AT ... directly in the script.
How can I have the SQL Server do the authentication automatically when opening a connection?
How can I make normal write operations work without OPENQUERY()?
Sorry for not adding detailed error messages, I will add them later maybe, when I have access to the server again... But they were not meaningful anyway, i.e. when the weird authentication was missing, it just said "could not insert" or "failed" instead of indicating any authentication issue.
How to get the real error messages that come from Sybase?
Details:
SAP Sybase SQL Anywhere 16 (OEM Authenticated Edition) <-> MS SQL Server 2014
EXEC 'SET TEMPORARY OPTION CONNECTION_AUTHENTICATION=''Company=...''' AT linkedserver
INSERT INTO OPENQUERY(linkedserver, 'SELECT column FROM table WHERE 0=1') VALUES ('')
...that's not nice.
Even more details:
This is how I created the linked server
This is the authentication I'm talking about

Cannot create trigger on linked server in SQL Server

I have one local database in SQL Server and one Oracle database as an linked server in SQL Server. I want to create a trigger on the linked server (Oracle database table) which will insert data into SQL Server table. This is what I have tried
CREATE TRIGGER TrgItemInsert
ON ORACLEDB..SYSTEM.ITEM
AFTER INSERT
AS
BEGIN
PRINT 'Something Happened to Table ITEM'
END
but I get the following error:
The object name 'ORACLEDB..SYSTEM.ITEM' contains more than the maximum number of prefixes. The maximum is 2.
Is this possible?
Is there any work around to achieve this task?
Connection to the linked server is working and I can query the data in the linked server using 'SELECT' statements.
Thanks in advance.

origin of a linked server

I used this query to determine what databases are using the 5 linked servers on a SQL server.
However, the results don't make sense to me. It is telling me that a server "DOMAIN" is being used by many databases for views, but when I look at the design of the view, I do not see [DOMAIN] in the SQL statement.
Example:
The query result shows me that the database [StrongMailTracking] depends on the linked servers [DOMAIN] and [SDMASQLSRV05.WISPUBS.UCG.COM] for the view [vw_SCP].
When I look at the design of [vw_SCP] I see:
SELECT DISTINCT ucontactid, vemail, vfirstname, vlastname, domain, vcompanymapped, vcompanyname
FROM SDMASQLSRV05.WISPUBS.UCG.COM.MarketingPromotions.dbo.selected_contacts_prelim AS a
When I go Linked Servers and expand DOMAIN, there aren't any tables or views. When I try to expand the System tables and views, I get an error:
Named Pipes Provider: Could not open a connection to SQL Server...
(Microsoft SQL Server, Error: 53)
Any thoughts on what's going on here?

Cannot connect to MS Access file from SQL Server 2008

I have been trying for the past week or so to import data programmatically to a SQL Server 2008 table from a Microsoft Access .mdb file. I have been getting nothing but errors, and solving one just reveals another. I made the file into a linked server, and now when I try to query it with:
Select * from OPENQUERY(Importdata, 'Select * from [IMBPieceBC]')
I get the error:
OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "Importdata" returned message "Cannot open database ''. It may not be a database that your application recognizes, or the file may be corrupt.".
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "Importdata".
I've read several suggestions to relink dlls in the registry, but I've done that, and I'm still getting the error. Is there anything else I can do to fix it, or at least figure out what is wrong?
Migrating the data to a SQL Server instance is not an option. The mdb files are generated by a third-party program, so there's nothing we can do about it.
I have a similar situation at my workplace - a third party application that maintains data in MDBs, but other applications needing access to it. How I've done it is that this 'intermediary' application has links to the SQL Server tables and the MDB tables. You could use either a query or a VBA written form event to transfer information from the MDB table(s) involved into your corresponding SQL Server tables using a INSERT INTO query, fitted with a SELECT FROM subquery providing the values being inserted.

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