Re: copying data from one server to another
- From: imorxr@xxxxxxxxx
- Date: Wed, 14 May 2008 21:52:28 -0700 (PDT)
On Apr 22, 8:49 pm, "Plamen Ratchev" <Pla...@xxxxxxxxxxxxx> wrote:
You can add linked server and use it to copy the table data across server.
Creating linked server is done using sp_addlinkedserver:
EXEC sp_addlinkedserver 'RemoteServer', N'SQL Server'
Based on security settings you may need to map remote server logins. This is
done using sp_addlinkedsrvlogin:
EXEC sp_addlinkedsrvlogin 'RemoteServer', 'false', 'LocalUser',
'RemoteUser', 'RemotePassword'
Then you just run a normal query referencing the linked server table with 4
part name:
INSERT INTO TargetTable
SELECT <columns>
FROM RemoteServer.RemoteDB.dbo.RemoteTable
HTH,
Plamen Ratchevhttp://www.SQLStudio.com
How if i need to : 'SET IDENTITY_INSERT ON' before execute insert
command ?
i have try it before :
SET IDENTITY_INSERT [remoteservername].Library2005.dbo.tblLanguages ON
--> will result error
[remoteservername].Library2005.dbo.sp_executesql N'SET IDENTITY_INSERT
dbo.tblLanguages ON' --> no error
That command executes without error, but the problem is that I cannot
perform the actual insert, because it is not within the execute
statement. In other words, the following doesn't work:
EXECUTE [remoteservername].Library2005.dbo.sp_executesql N'SET
IDENTITY_INSERT dbo.tblLanguages ON'
INSERT INTO [remoteservername].Library2005.dbo.tblLanguages
(colLangID, colEnglish, colGerman, colSpanish)
SELECT colLangID, colEnglish, colGerman, colSpanish FROM tblLanguages
This results in the error:
Msg 7344, Level 16, State 1, Line 2
OLE DB provider 'SQLOLEDB' could not INSERT INTO table
'[remoteservername].[Library2005].[dbo].[tblLanguages]' because of
column 'colLangID'. The user did not have permission to write to the
column.
The remote server is linked correctly on my end via the
sp_addlinkedserver and sp_addlinkedsrvlogin. Is there any way to force
the remote server to turn IDENTITY_INSERT ON permanently and then let
me execute as many INSERTS as I want and then turn it back OFF?
.
- Follow-Ups:
- Re: copying data from one server to another
- From: Erland Sommarskog
- Re: copying data from one server to another
- From: Plamen Ratchev
- Re: copying data from one server to another
- Prev by Date: Re: SQL 2005 on Windows Server 2008 - Slow Connection Time
- Next by Date: Re: copying data from one server to another
- Previous by thread: create dynamic variable in procedure
- Next by thread: Re: copying data from one server to another
- Index(es):
Relevant Pages
|