SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


sp_addlinkedserver in Stored Procedure


sp_addlinkedserver in Stored Procedure

Author
Message
jimkiely
jimkiely
Valued Member
Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)

Group: General Forum Members
Points: 56 Visits: 10

I need to create a stored procedure on my development sql server that does the following;

1.) Deletes all records from tblMonthlySales on my Production Server.

2.) Inserts records into my tblMonthlySales(Production Server) from tblMonthlySales(Development server).

This is what I tried to do and it won't work.

CREATE PROCEDURE [spTransMonthlySales] AS
EXEC sp_addlinkedservers 'ITCHY', N'SQL Server'

DELETE
FROM Itchy.BreakTheBank3.dbo.tblMonthlySales

INSERT Itchy.BreakTheBank3.dbo.tblMonthlySales
SELECT *
FROM Scratchy.BreakTheBank3.dbo.tblMonthlySales

GO

Any ideas!





Allen Cui-55137
Allen Cui-55137
SSCrazy Eights
SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)SSCrazy Eights (8.7K reputation)

Group: General Forum Members
Points: 8749 Visits: 1

"EXEC sp_addlinkedservers 'ITCHY', N'SQL Server'"

There is no "s" in sp_addlinkedserver command.

Or use openrowset, for example.

SELECT a.* into Test2
FROM OPENROWSET('SQLOLEDB','tstsql01'; 'yourloginid' ; 'yourpassword' ,
'SELECT * FROM northwind..orders') AS a





anvie
anvie
Old Hand
Old Hand (394 reputation)Old Hand (394 reputation)Old Hand (394 reputation)Old Hand (394 reputation)Old Hand (394 reputation)Old Hand (394 reputation)Old Hand (394 reputation)Old Hand (394 reputation)

Group: General Forum Members
Points: 394 Visits: 110
Hello,

Make sure you have the rights to access the remote server or the server you are trying to linked. You also should consider creating login for the linked server.

Query Format:
-- Create Linked server
EXEC master.dbo.sp_addlinkedserver
@server = N'Server Name',
@srvproduct=N'SQL Server'


-- Create Login for the linked server
EXEC master.dbo.sp_addlinkedsrvlogin
@rmtsrvname=N'Server Name',
@useself=N'False',
@locallogin=N'Local User Name',
@rmtuser=N'Remote User Name',
@rmtpassword='Remote Password'

Let me know if you still having problem with this.
dat.tomytom
dat.tomytom
SSC Rookie
SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)

Group: General Forum Members
Points: 28 Visits: 1
I want connection database remove.
Following detail information remove server:
Data source=MyNgan-PC\SQLEXPRESS( Example IP :192.168.186.186)
Northwind, password=sa; uid=sa
Help me! How use detail sp_addlinkedserver
thank!!
dat.tomytom
dat.tomytom
SSC Rookie
SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)SSC Rookie (28 reputation)

Group: General Forum Members
Points: 28 Visits: 1
I want connection database remove.
Following detail information remove server:
Data source=MyNgan-PC\SQLEXPRESS( Example IP :192.168.186.186),
database=Northwind, password=sa; uid=sa
Help me! How use detail sp_addlinkedserver
thank!!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search