<p>I've got a database server that I am unable to connect to using the credentials I've been provided. However, on the staging version of the same server, there's a linked server that points to the production database. Both the staging server and the linked server have the same schema.</p>

<p>I've been reassured that I should expect to be able to connect to the live server before we go live. Unfortunately, I've reached a point in my development where I need more than the token sample records that are currently in the staging database. So, I was hoping to connect to the linked server.</p>

<p>Thus far in my development against this schema has been against the staging server itself, using Subsonic objects. That all works fine.</p>

<p>I can connect via SQL Server Management Studio to that linked server and execute my queries directly. I can also execute 'manual" queries in C# against the linked server by having my connection string hook up to the staging server and running my queries as </p>

<p>SELECT * FROM OpenQuery([LINKEDSERVER],'QUERY')</p>

<p>However, the Subsonic objects are what's enabling me to bring this project in on time and under budget, so I'm not looking to do straight queries in my code.</p>

<p>What I'm looking for is whether there's a way to state the connection string to the linked server. I've looked at lots of forum entries, etc. on the topic and most of the answers seem to completely gloss over the "linked server" portion of the question, focusing on basic connection string syntax.</p>

[{'answer_id': 18325, 'author': 'SQLMenace', 'author_id': 740, 'author_profile': 'https://Stackoverflow.com/users/740', 'pm_score': 0, 'selected': False, 'text': "<p>creating a linked server from .NET doesn't make any sense since a linked server is nothing but a connection from one sqlserver to another server (sql, file, excel, sybase etc etc), in essence it is just a connection string (you can impersonate and do some other stuff when creating a linked server). </p>\n"}, {'answer_id': 18395, 'author': 'JasonS', 'author_id': 1865, 'author_profile': 'https://Stackoverflow.com/users/1865', 'pm_score': 2, 'selected': False, 'text': "<p>I don't believe that you can access a linked server directly from an application without the OpenQuery syntax.  Depending on the complexity of your schema, it might make sense to write a routine or sproc to populate your staging database with data from your live database.</p>\n\n<p>You might also consider looking at Redgates SQL Data Generator or any other data gen tool.  Redgates is pretty easy to use.</p>\n\n<p>One other idea - can you get a backup of the live database that you can install in development to do your testing?  If its just data for development and testing that you seek, you probably want to stay away from connecting to your production database at all.</p>\n"}, {'answer_id': 18695, 'author': 'TheEmirOfGroofunkistan', 'author_id': 1874, 'author_profile': 'https://Stackoverflow.com/users/1874', 'pm_score': 2, 'selected': False, 'text': '<p>Create testing stored procedures on server B that reference the data on server A via the linked server.  e.g. if your regular sproc references a table on Server B say:</p>\n\n<pre><code>databaseA.dbo.tableName\n</code></pre>\n\n<p>then use the linked servername to reference the same database/table on server A:</p>\n\n<pre><code>linkedServerName.databaseA.dbo.tableName\n</code></pre>\n\n<p>If server A is identical in its database/table/column names than you will be able to do this by some quick find/replace work.</p>\n'}, {'answer_id': 1058306, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>One Way is to create two connection strings and access the approperiate database when required.\nSecond option is create connection for Database A only and create a link server For Databse B in Database.good article, i really like it.  I am doing a bit on research about Asp.net connection and i found also macrotesting www.macrotesting.com to be very good source.  Thanks for you article.....</p>\n\n<p>Regards...\nMeganathan .J</p>\n'}]
['https://Stackoverflow.com/questions/18167', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1124/']