Where are SQL Linked Server view definitions? - sql

I've migrated and moved linked servers before, but never had to modify one, so this issue is mostly foreign to me.
Here's the situation (with table names obscured but consistent):
SQL Linked Server SQLXYZ1-> Catalog XYZ -> View HRIS.ZZ_VIEWNAME
This "view" definition maps to a DB2 table on the AS/400 called DB2.TABLENAME.
Here's the issue: I added a new column to the DB2 table DB2.TABLENAME, but when it comes through the linked server (via this view), the new column is coming through wrong because the linked server side of the view definition doesn't know about it.
If I right-click and generate a Select statement from view HRIS.ZZ_VIEWNAME on the SQL linked server side, the columns that come back is the OLD definition of the table that no longer matches DB2.TABLENAME. There's also the fact that the linked server side of things has a prefix of "ZZ_" on the table name, which someone had to type in somewhere, but I can't figure out where... So if ZZ_VIEWNAME is a "view" that the linked server sees, how can I find out where this view is? Is it a SQL view or DB2 view?
My question is: Where is the "definition" of the view that the SQL linked server sees?
I've asked our top SQL manager here, who insisted it's not in SQL, but must exist on the AS/400.
I've asked our top AS/400 manager here, who insisted that such a thing is not done on the AS/400/DB2 and must exist on the SQL side.
So essentially, nobody knows where this definition is.
As someone who doesn't know linked servers and the experts here can't agree, where is the definition of external view that a SQL linked server sees?
Thanks!

Turns out there was another dev's intermediary linked server in the middle, so my question was invalid from the very start.
Someone overarchitected a disaster of a database which is apparently going:
Application -> SQL server view -> Linked Server -> SQL server view -> Synonym in an incorrect database -> Linked Server -> DB2 table

Related

Query SQL Linked Server only pulling data from one server

I have four SQL Servers that are named in the following way:
dbs
dbs2
dbs3
dbs4
I have a table that is on dbs3 called table1 in database1. This table does not exist on the other servers. However when I run the query:
select *
from dbs.database1.dbo.table1 (or any of the database servers)
it returns the results as if I queried the existing table on dbs3. It is like the DBMS is ignoring the 4 part nameing in the query and returning the results from table on dbs3 no matter which server I try to designate in the 4 part naming convention. Any ideas what could be going on here. The servers appear in the linked servers list.
If you can make changes without breaking stuff (or if it's already broken enough in your opinion), I recommend recreating your linked servers. If your linked server is another SQL Server, you can do
exec sp_dropserver 'dbs';
exec sp_addlinkedserver 'dbs';
This creates a linked server definition with the default configuration, which is appropriate for most applications (and can still be tweaked afterwards).

Updating SQL server from Access front end

This is pretty new to me. I have an Access database that I was to upsize to a SQL server but to keep the Access front end to make this application available remotely. I have imported the data in the SQL database using SSMA which looks to be fine. However, when adding a new record to the Access frontend, the SQL server is not being updated. Am I missing something? I (think I) have linked the tables together but still not joy.
Any help would be great. Thank you
If the data is being stored, but not on the SQL Server then you almost certainly have not linked the tables correctly.
On your Access front end your starting point should be no tables (unless you have some tables deliberately reserved for the front end for some reason). You then link to the back end tables (because you said 'linked the tables together', I suspect you have copies of the tables still in your front end).
During the linking process, Access will confirm if each link is established successfully.
It sounds like you haven't imported the data from MS Access to SQL yet.
Check out the SQL Server Migration Assistant(SSMA) on how to do that.
http://www.microsoft.com/sqlserver/en/us/product-info/migration-tool.aspx#Access.
First you need to migrate the data to SQL and then you link the data in SQL to MS-Access.
Once the tables are linked appropriately it will update in SQL as it is entered in Access.
To link the tables you need to first setup an ODBC and then in access select external data -> import -> more -> ODBC Database and select "Link to the data source by creating linked tables"
Check out this link: http://www.fontstuff.com/ebooks/free/fsLinkingToSQLServer.pdf to make sure you did it right.
I had this problem before.
Create a primary key for every table you want to edit in Access. set identity specification and Identity increment by 1 or ? (you can find this setting in column properties) Make sure data type for primary key is int.
All boolean value fields should have constraint set to 0 and no null values.

How to retrieve records from server database into local database

I have a little problem. I want to create a query in my local database (tijdsregistratie.mdf) to retrieve rows from my server database (IT Solutions Develop.dbo) on server itshou-dev03\sql2008.
But I don't know how to connect to the server database. I tried it like this :
select TOP 10 * from [IT Solutions Develop].dbo.[IT Solutions BVBA$Planning]
.. but it gives me this error :
Invalid object name 'IT Solutions Develop.dbo.IT Solutions
BVBA$Planning'.
One way is to link the servers:
http://msdn.microsoft.com/en-us/library/ms188279.aspx?ppud=4
You can also define linked servers by using SQL Server Management
Studio. In the Object Explorer, right-click Server Objects, select
New, and select Linked Server. You can delete a linked server
definition by right-clicking the linked server name and selecting
Delete.
This is the process by which you tell SQL Server where another server is and how to connect to it. You can do this in SQL Server Management Studio or in T-SQL. You can then refer to the linked server by a four part name (similar to what is in your question):
[LinkedServerName].[Database].[Schema].[Object]

SQL Server 2005 Linked server not finding tables

I have a linked server where I can clearly see all the databases and tables, so I know the server is properly linked. However, when I try to execute a query, it says invalid object name, at the linked server's table.
The linked server is aliased as TCS, therefore, my query takes that table as
FROM [TCS].dbo.table as b
I have also tried including the database name also as FROM [TCS\db1].dbo.table.
What am I missing here?
Try including the DB name like so:
FROM [TCS].db1.dbo.table as b
I don't think you can specify the DB using a slash.
I would also check to make sure your security settings for the linked server are allowing your account to connect. This article touches on how to do that.
either:
the user (used for the link) doesn't have access to the table; Grant access;
the default DB on the server doesn't have the table. You have to change it to the relevant one or included in the db in the name: [TCS].DATABASE.dbo.table as b;

Create View using Linked Server db in SQL Server

How can I create View on Linked Server db. For Example I have a linked server [1.2.3.4] on [5.6.7.8]. Both db servers are SQL Sserver 2005. I want to create View on [5.6.7.8] using table on linked server.
EDIT:
On creating using full name, [1.2.3.4].db.dbo.table, I am getting this error.
SQL Execution Error.
Executed SQL statement: SELECT * FROM 1.2.3.4.db.dbo.table (YOu can see brackets are not there.)
Error Source: .Net SqlClient Data Provider
Error Message: Incorrect syntax near '0.0'. ---> part of IP address.
I am just creating this in ManagementStudio, not using it because it is not created yet. I Have changed IP. In image you can see there are not brackets around IP but I given it and on error these brackets are removed.
Thanks.
You need to use the four part qualified name: linkedserver.database.schema.table
SELECT * FROM [1.2.3.4].Northwind.dbo.Customers
Here is an MSDN article about accessing object names.
You might want to try manually creating the view, rather than using the SQL Management tools:
CREATE VIEW [dbo].[sywx]
AS
SELECT *
FROM [1.2.3.4].Atia.dbo.IpPbxDCR
GO
I also recommend that you use a name, if possible, for the linked server rather than using the IP address.
Its a SQL Management Studio Issue.
If you try to create the view using management studio NEW VIEW then you get that error incorrect syntax.
But if you use SQL Query:
CREATE VIEW [dbo].[viewname]
AS
SELECT *
FROM [0.0.0.0].database.dbo.table
GO
then it will work.
To test you will see the view created when you refresh views.
If you just do a select query from the view you will see the view return results.
But if you try to go into design mode for that view and try executing the design query the error will pop up again even though the view was successfully created.
If the linked server is set up, you just reference tables on it using a four-part qualified name:
linkedserver.database.schema.table
So if your linked server name is [0.0.0.0], you can reference a table as:
[0.0.0.0].database.schema.table
your main problem is naming your Link Server with numbers (IP address). The only way that worked for me was using an alphabetical name for my Link Server without any dot '.'
You can use these lines of code to add your link server and authentication:
EXEC sp_addlinkedserver
#server='TEST_LINK',
#srvproduct='',
#provider='SQLNCLI',
#datasrc='tcp:0.0.0.0'
EXEC sp_addlinkedsrvlogin
#useself='FALSE',
#rmtsrvname='TEST_LINK',
#rmtuser='user',
#rmtpassword='secret'
You can find the original answer here
For linked servers using the periods for a web service name - this won't work.
The code details and steps of the difference is posted at:
http://www.access-programmers.co.uk/forums/showthread.php?t=260764
e.g. FROM [V2.EGG.COM]..[NAT_DBA].[NV_WELLS]
In SSMS 2008, the square brackets around the [V2.EGG.COM].. are removed by the editor. Then the update failes because it is more than 4 parts.
Have searched in vain to find a work-around.
The Script that does work is posted at the link above.
You can also just drag and drop the table/view object from the linked server into your view and Management Studio will create the four part reference for you.
You need to define a Linked Server before you can access it, since the linked server entry also contains the authentication details.
After creating a linked server, you can access its databases and their objects using the dot notation servername.database.[owner].object