Solved

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

Posted on 2014-11-06
7
202 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
  • 3
  • 3
7 Comments
 
LVL 142

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
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
LVL 142

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 142

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now