Cannot select data on linked SQL Server using SQL authentication - sql-server

I have created a linked server using SQL authentication and the connection seems to work as I can select from the master database.
However, I cannot select from a specific database to which the SQL account I use in the linked server has access.
I tried following the suggestions in other similar posts in here but to no avail. Any help really appreciated. I am attaching a screenshot of the security settings.
Thanks.

This is a bit of a long shot, but since no one else is answering so we'll give it a go. If you restored the DB from another server, it's possible the ssid's are out of whack. Switch context to the DB on the linked server and run the following.
EXEC sys.sp_change_users_login #Action = 'Report'
If any results show up with the login in question, remove it by running this.
EXEC  sp_change_users_login #Action='update_one', #UserNamePattern='your_user',#LoginName='your_login';

Related

Error in SQL Server when connecting to PowerBI Datamart [Unsupported sql function USER_NAME]

I have connected to a Datamart via SSMS. Behind the Datamart is an Azure SQL database.
I am trying to find out my username. I used the following query:
SELECT USER_NAME();
I get this error:
Unsupported sql function USER_NAME. Line:1, Position:8
I have combed the internet but I have not come across something that works yet.
in MS SQL SERVER you must use
SELECT CURRENT_USER;
The op wrote in the comment, that he needed to close the open query box and open a new one, after that it works, like a charme.
or to get the windows user mame of the logged in user
SELECT SUSER_NAME() LoggedInUser

DB Link from Oracle to MS Server

I am new to this forum and already searched for 45 minutes to find a solution for my problem. I hope you can help me.
A Gateway to a remote Microsoft SQL Database was installed on a Oracle Server (Oracle 12c). The tsnnames.ora file was appropiately set up.
For the connection, I created a database link (In the Oracle DB) as follows:
CREATE DATABASE LINK TEL CONNECT TO "fb_B2C" IDENTIFIED BY "passwort" USING 'dg1msql';
When I now execute the Select statement:
SELECT "name" FROM "sys"."databases"#TEL
it shows me the according databases. Among others, I can see the AB_Colors database.
Now, I want to select a view in the AB_Colors database.
Due to the fact I can connect to this database via Excel, I know that in the database AB_Colors, there are 10 Views(A,B,C,..). I would like to select the View C from the database AB_Colors via the DB LInk.
Owner of the View is b2b.
How do i need to formulate the select statement to do it?
I already tried different writings:
SELECT * FROM b2b.C#TEL;
SELECT * FROM "AB_colors"."b2b"."C"#TEL;
SELECT * FROM [AB_Colors].[b2b].[C]#TEL;
The common error message is: View/Table does not exist
I highly appreciate your help,
Fedja
This is the correct format
SELECT * FROM "b2b"."C"#TEL;
The issue maybe because the database you want to select from is not the one specified in the gateway for dg1msql. You can't add the database name to the query so you must specify it in the gateway connection.
This is defined in
$ORACLE_HOME/dg4msql/admin/initdg4msql.ora
where you should check HS_FDS_CONNECT_INFO

Connect to a linked database from a net core application

I'm trying to connect to a linked server from .net core.
I connect to my SQL Server, but I cannot reach the Oracle Database linked on it.
For example, I can connect to an actual SQL Server Database with the cnnStr:
"Server=foo\SQLEXPRESS;Database=DatabaseName;Trusted_Connection=True;MultipleActiveResultSets=true"
But if I change the Database parameter to the linked server, I get an error "Cannot open database "dbLINK" requested by the login. The login failed"
Does anyone knows how to connect to a linked database?
Thanks in advance
I believe the right way to do that is either creating views that access your linked server or access your linked server data directly from your query, for example, SELECT * FROM OPENQUERY([LINKEDSERVERNAME], 'SELECT Id, Name, Age from USER');
It`s important to point out that views are probably gonna be a better practice in this case. If you change anything related to your linked server in the near future, you'll need to change things in only one place.

Cannot See Stored Procedure on Linked Server

First, I know the syntax of calling a procedure on a linked server and I am familiar with the RPC and RPC Out server options at a basic level. What I am being told is that a procedure I created cannot be seen by navigating the tree of the linked server.
One caveat is I do not have access to the server where this person is working which is linked to the server on which I have the procedure - I hope that is clearly stated. At this time he is getting the "not configured for RPC" error on execution and I have told him to check the linked servers options. So ultimately, do the RPC linked server options control whether the procedure can be seen?
I've been told that other views can be seen. Also, I am confident it is not a permissions issue. The user involved has access to a role which has access to my procedure.
Thank you for your time.
In the Linked Server, Properties, Server Options there are two RPC settings.
Set them both to true.
What do you mean by do not have access?
You cannot Connect to that server?
That is how I tested this.
Connect to any server, create a Linked Server back to yours, and test.
This is true:
In the Linked Server, Properties, Server Options there are two RPC settings.
Set them both to true.
You also need to verify that the credentials used inside the linked server connection has rights on the linked server.
Grant connect, and access to the database that has the stored procedures that you need access too. You will then grant execute to the procedures you need to run.
If you have connection issues, open SSMS using the credentials you have used to create the linked server on the database server you are trying to link from and verify connectivity and database access. If you can see the objects your after, then the linkedserver connection is the problem. Try creating a new one and see if you have better luck that way.

Grouping sys.dm_exec_connections by database (it's not quite like sys.sysprocesses)

Following on from my last question:
I've written some code to upgrade a SQL Server database. Before I upgrade the database, I plan to limit access to the database with the following statement:
ALTER DATABASE Test SET SINGLE_USER WITH ROLLBACK IMMEDIATE
Before running this code, I'll give the user an opportunity to opt out. At the time of prompting the user, I thought it would be nice to show the list of active connections (continuously polled at a set interval); providing the user with a tool to identify applications/users they would like to boot off the server before proceeding.
In SQL 2000, you can use the sys.sysprocesses table to see all connections that apply to a database. This includes connections that have no active request (like when you open a Query Analyser window and select a database).
However, using:
sys.dm_exec_connections
sys.dm_exec_sessions; and
sys.dm_exec_requests
I couldn't figure out a way to achieve the same outcome. It appears that these views only tie connections to a database through a request. Is there a way to mimic the behaviour of sys.sysprocesses? I'd prefer not to use this table for SQL Server 2005/2008 databases.
Er... I recommended these for your other question.
Sorry, but, I've found out that you still have to use sysprocesses
It's logged as a bug in Microsoft Connect 144515 to be fixed, I found it here
Personally, I still use sysprocesses because I'm comfortable with it, however lazy and luddite that may be...

Resources