Solved

How to add tables from different SQL Server instances to a View

Posted on 2014-11-06
7
212 Views
Last Modified: 2014-11-13
I  need to create a Stored Procedure in one database flosserv2\MyDatabases that will include tables from that database and also a table from another database that is in another SQL instance floserv2\invu.

The sp will be in floserv2\MyDatabases (2005) and will need to also include a table from floserv2\invu (2008 express).

I can see the databases from each SQL instance but can only add tables to views and sp's in floserv2\MyDatabases, I cannot add any tables from floserv2\invu.

I get the message 'Could not find server 'ServerName' in sysservers. Execute sp_addlinkedserver to add the server to sysservers. '

Not too sure what to do and where.
0
Comment
Question by:TeDeSm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40425839
how to set up a linked server:
tech reference: msdn.microsoft.com/en-us/library/aa560998.aspx
video guide: www.youtube.com/watch?v=w1bHTUVt6bA

once that is set up correctly, say on instance 1 you created a linked server to instance 2, you can query
select * from instance2.database_from_instance_2.dbo.some_table
0
 
LVL 2

Expert Comment

by:Pratik Makwana
ID: 40427833
Looks like some prefix error.... You need to add like....

SERVERNAME.DATABASENAME.DBO.TABLENAME
0
 

Author Comment

by:TeDeSm
ID: 40432882
I have added a user on floserv2\invu and changed permissions so that I can now see the database in Visual Studio Server Explorer. I am not able to drag and drop a table onto a View design though. I have also created a linked server on floserv2\MyDatabases so is it possible to connect to that in VS?
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40433075
> I am not able to drag and drop a table onto a View design though.
that is normal, the View Designer can only take local tables and views
0
 

Author Comment

by:TeDeSm
ID: 40434699
Hi Guy, thanks for the head up on views, I was not aware of that issue.

I am having trouble designing a view in VS save to sql2005instance linking some_table to sql2008instance.another_table. This view will be used in a VS project to produce a report.
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 40436766
you have to run the create view from T-SQL...

in case you want to work/use this remote table regularly, you should consider creating a (local) view using a select * from the remote table. that way, you could use that view in your designer
0
 

Author Closing Comment

by:TeDeSm
ID: 40439535
Hi Guy. Getting the syntax correct was a bit of an issue, in creating the linked server and in creating the view.
The solution is:

Create Linked Server
In SSMS select the server where the View or Stored Procedure is required, create a Linked Server. In my case the sp is in floserv2\flosql and the other table I require is in floserv2\invu. The Linked Server was created in floserv2\flosql using the SQL Server option and using the name FLOSERV2\INVU, security '..using the login's current security content', RPC = True. Although i'm not sure if the RPC should remain at the default of False.

To Reference the Table in the Linked Server
Interestingly selecting 'All Columns' appeared to literally select each column. The syntax for the Linked Server was critical and took a few tries in getting correct. View designer in Visual Studio appeared to 'help' in this respect.
SELECT        TOP (100) PERCENT METAID, DTADDED, A28, A29, A30, A31, A32, A35, A34_TMP, A59_TMP, A59
FROM            [FLOSERV2\INVU].series6.dbo.TU6_ATTRIBUTE AS TU6_ATTRIBUTE_1

I then added the the other tables and linked to the table from the Linked Server, as I only need to test for column 'A29 Is Null' I removed the other columns from the view. Run the SQL and all was correct.

As an 'Accidental DBA' all the above was completly new to me.
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question