Click here to Skip to main content
15,884,998 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to avoid the insertion issue occuring while using Linked Server in SQL?

I have created a Linked Server and when I try to insert using below script it's not working.

Script is as follows:
SQL
declare @sql nvarchar(1000)='SET IDENTITY_INSERT dbo.EMPID ON
INSERT INTO [TEST3].test3.dbo.EMPMASTER(
[EmpId],[EmployeeName],[DeptId])
SELECT[EmpId],[EmployeeName],[DeptId]
FROM [TEST3].test3.dbo.EMPMASTER
SET IDENTITY_INSERT dbo.EMPID OFF'
EXEC sp_executesql @sql
Posted

1 solution

Hi... Do you have proper execution rights on your user id.. what error you are facing...
 
Share this answer
 
Comments
Kandiya 24-Feb-15 8:18am    
I have admin privileges to do these. But still getting the error:
Cannot find the object "dbo.EMPMASTER" because it does not exist or you do not have permissions.
manak chand 24-Feb-15 9:07am    
How you can Insert and select from same table in same query.. I think this might not be possible..
Kandiya 24-Feb-15 23:33pm    
It happend accidentally. Here insertion of data is done to a table in the Linked Server NESTIT-319-E from the DB Server NESTIT-327.
declare @sql nvarchar(1000)='SET IDENTITY_INSERT dbo.EMPMASTER ON
INSERT INTO [NESTIT-319-E].test3.dbo.EMPMASTER(
[EmpId],[EmployeeName],[DeptId])
SELECT[EmpId],[EmployeeName],[DeptId]
FROM [NESTIT-327].test1.dbo.EMPMASTER
SET IDENTITY_INSERT dbo.EMPMASTER OFF'
EXEC sp_executesql @sql
manak chand 25-Feb-15 1:27am    
On which server you were running your queries..
is this statement work..

SELECT[EmpId],[EmployeeName],[DeptId]
FROM [NESTIT-327].test1.dbo.EMPMASTER

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900