Solved

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

Posted on 2014-11-06
7
207 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 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

808 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