SQL server DB link

Source: Internet
Author: User

 

-- Add link

Exec sp_addmediaserver @ server = 'dblinkcompalaps ', @ srvproduct = '', @ provider = 'sqloledb', @ datasrc = 'cetebiddb', @ catalog = 'bccdb'

Exec sp_add1_srvlogin 'dblinkcompalaps ', false, null, 'ebid ','******'

 

EXEC master. dbo. sp_addmediaserver @ server = n' link _ cetebiddb ',

@ Srvproduct = n'sqldbm', @ provider = n'sqloledb', @ datasrc = n'cetebiddb ',

@ Provstr = n'user ID = ebid; Password = ******'

-- Drop link

Exec sp_droplinkedsrvlogin DBLinkCompalAPS, Null

Exec sp_dropserver DBLinkCompalAPS

 

-- Select

Select * from sys. servers

 

Select top 1 * from DBLinkCompalAPS. bccdb. dbo. BCC_Admin_CartStyle

 

 

--

Proc

 

SET QUOTED_IDENTIFIER ON

GO

SET ANSI_NULLS ON

GO

 

 

/*************************************** ***********

Name:
Usp_Create_DBLink_DBLinkCompalAPS

Purpose: Created DBLik
ControlDB

Used table:
APSCN10.dbo. pl_controlDB_inf

**************************************** **********/

ALTER proc
[Dbo]. [usp_Create_DBLink_DBLinkCompalAPS]

@ Parm_plant
Nchar (04)

As

Begin

Set nocount
On

Declare @ server nvarchar (10), @ db
Nvarchar (10), @ uid nvarchar (10), @ pwd nvarchar (50), @ web_uid nvarchar (10), @ web_pwd
Nvarchar (20)

Select top 1
@ Server = ControlDB_Server_name


, @ Db = ControlDB_DB_name


, @ Uid = ControlDB_uid


, @ Pwd = ControlDB_password


, @ Web_uid = substring (';' + aps_db_connection + ';', charindex ('; Uid =', ';' + aps_db_connection + ';') + len ('; uid = '), charindex ('; ','; '+ aps_db_connection +'; ', charindex ('uid =', ';' + aps_db_connection + ';')) -(charindex ('; Uid =', ';' + aps_db_connection + ';') + len ('; Uid = ')))


, @ Web_pwd = substring (';' + aps_db_connection + ';', charindex ('; Pwd =', ';' + aps_db_connection + ';') + len ('; pwd = '), charindex ('; ','; '+ aps_db_connection +'; ', charindex ('pwd =', ';' + aps_db_connection + ';')) -(charindex ('; Pwd =', ';' + aps_db_connection + ';') + len ('; Pwd = ')))

From
Pl_controlDB_inf

Where
Plant = @ parm_plant

Declare @ SQL
Nvarchar (2000)

 

Exec sp_droplinkedsrvlogin
DBLinkCompalAPS, Null

 

Exec sp_dropserver
DBLinkCompalAPS

 

Set @ SQL = 'exec sp_addmediaserver
@ Server = ''dblinkcompalaps '', @ srvproduct = ''', @ provider = ''sqloledb'', @ datasrc = ''' + @ server + ''''

Exec
(@ SQL)

 

Set @ SQL = 'exec sp_addjavassrvlogin
''Dblinkcompalaps '', ''false'', null, ''' + @ web_uid + ''', ''' + @ web_pwd + ''''

Exec
(@ SQL)

Set @ SQL = 'exec sp_addjavassrvlogin
''Dblinkcompalaps '', ''false'', null, ''' + @ uid + ''', ''' + @ pwd + ''''

Exec
(@ SQL)

 

Set nocount
Off

End

 

 

GO

SET QUOTED_IDENTIFIER OFF

GO

SET ANSI_NULLS ON

GO

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.