Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-11-06
7
Medium Priority
?
221 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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

972 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