Skip to main content

Create Linked Server using T-SQL

Create Linked Server using T-SQL
While the linked server can be created using the built-in wizard of the Management Studio, it can also be created using TSQL statements as in the following listing (run both statements, the first one creates the linked server and the second the logins).

Exec master.dbo.sp_addlinkedserver
@server=N’localhost’,
@srvprodcut=N’MySQL’,
@provider=N’MSDASQL’,
@datasrc=N’MySQL’

Exec master.dbo.sp_addlinkedserverlogin
@server=N’localhost’,
@locallogin=NULL,
@rmtuser=N’user’,
@rmtpassword=N’<your password>’
@rmtsrvname=N’localhost’

Comments

Popular posts from this blog

Remove Duplicate Row in Sql Query

Method 1: -- Create Sample Table DECLARE @ table TABLE ( data VARCHAR ( 20 ) ) -- Insert Some Data INSERT INTO @ table VALUES ( 'not duplicate row' ) INSERT INTO @ table VALUES ( 'duplicate row' ) INSERT INTO @ table VALUES ( 'duplicate row' ) -- Find out Duplicate rows in table : SELECT   data , COUNT ( data ) nr FROM     @ table GROUP BY data HAVING   COUNT ( data ) > 1 -- Remove Duplicate rows from table SET NOCOUNT ON SET ROWCOUNT 1 WHILE 1 = 1    BEGIN       DELETE    FROM @ table       WHERE     data IN ( SELECT   data                                FROM     @ table            ...

Change Key Dynamically in Web.Config

System.Xml; private void SetConfigSettings() { string path = Server.MapPath("Web.config"); string newConnectionString = @"Server=local;Database="+txtDatabaseName.Text+";Trusted_Connection=true"; XmlDocument xDoc = new XmlDocument(); xDoc.Load(path); XmlNodeList nodeList = xDoc.GetElementsByTagName("appSettings"); XmlNodeList nodeAppSettings = nodeList[0].ChildNodes; XmlAttributeCollection xmlAttCollection = nodeAppSettings[0].Attributes; xmlAttCollection[0].InnerXml = txtKey.Text; // for key attribute xmlAttCollection[1].InnerXml = newConnectionString; // for value attribute xDoc.Save(path); // saves the web.config file }