3

Possible Duplicate:
SQL - Connect to Linked Server with Named Instance

I want to connect to a Remote Server DB using Linked Servers. I want this connection to be done by a C# program. How to connect these Linked Servers in C#?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Shami
  • 324
  • 2
  • 8
  • 19
  • 3
    what do you mean by connecting? The idea of linked server is to connect on server A, and execute queries on server B while connected to A... – Steve B Jul 19 '12 at 09:31
  • @Ethan - http://stackoverflow.com/questions/29795658/how-to-use-openquery-in-c-sharp/29796186#29796186 – Zameer Ansari Apr 22 '15 at 12:17

2 Answers2

4

A linked server is an object on a SQL Server instance, so if you connect to that instance you can query the linked server as if you were quering any other object on one of the instance's databases.

here is an example:

SELECT * 
FROM OPENQUERY ( <linked_server>, 'select code, name, from your_table')

Not sure if this is the answer you were looking for, maybe if you provide more details of your scenario e can help you a little bit more

Diego
  • 34,802
  • 21
  • 91
  • 134
3

You can do it in sql just like an other Sql Query apart from giving linkedserver name in it, so the connection string remain the usual way we use without a linked server Here is nice site that gives various types of connectionstrings

SELECT * FROM linkedServerName.TheDatabaseName.dbo.TheTableName
HatSoft
  • 11,077
  • 3
  • 28
  • 43