Solved

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

Posted on 2014-11-06
7
196 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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

19 Experts available now in Live!

Get 1:1 Help Now