Rod Astrada
Rod Astrada

Reputation: 479

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

Upvotes: 1

Views: 1687

Answers (1)

Alan Silva
Alan Silva

Reputation: 139

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.

Upvotes: 3

Related Questions