how to undo sp_addlinkedserver abc,'SQL Server'? - sql-server

Wow i was just playing around with sp_addlinkedserver and i accidentally ran this command: sp_addlinkedserver abc,'SQL Server'
1) i had command(s) completed successfully.. but what happened?
2) how do i undo what i did?

You created a link to a server named abc.
You could try to query the server across this link using a command such as:
select *
from abc.master.information_schema.tables
But (unless you really do have a server called abc) it'll return you a message similar to:
OLE DB provider "SQLNCLI10" for linked server "abc" returned message
"A network-related or instance-specific error has occurred while
establishing a connection to SQL Server. Server is not found or not
accessible. Check if instance name is correct and if SQL Server is
configured to allow remote connections. For more information see SQL
Server Books Online.".
You can view your linked server in SSMS under Server Objects>>Linked Servers in the Object Explorer.
To get rid of the linked server, use the following statement:
sp_dropserver abc

You now have a linked server called abc
To remove, use sp_dropserver (There is no sp_droplinkedserver). Thus:
EXEC sp_dropserver 'abc', 'droplogins'

You added the Linked Server, see here about using it. Briefly, Linked servers used to obtain the ability to make distributed queries between your and linked servers:
SELECT MyServer.MyDatabase.dbo.Table1.Field1,
LinkedServer.MyDatabase.dbo.Table2.Field2
FROM MyServer.MyDatabase.dbo.Table1
INNER JOIN LinkedServer.MyDatabase.dbo.Table2
ON MyServer.MyDatabase.dbo.Table1.ID=LinkedServer.MyDatabase.dbo.Table2.ID

Related

SELECT Query between two different servers

I want to pull out data from different tables from different servers. I took a query at V5\SQL2014 Server and run these following to connect to V5_27\SQL2005 Server
EXEC sp_addlinkedserver
#server= 'V5_27\SQL2005',
#srvproduct='V5_27\SQL2005',
#provider='SQLNCLI',
#datasrc='tcp:0.0.0.0'
EXEC sp_addlinkedsrvlogin
#useself='FALSE',
#rmtsrvname='V5_27\SQL2005',
#rmtuser='sa',
#rmtpassword='123'
SELECT * FROM Stk006,[V5_27\SQL2005]..[TESTACC].Stk006
It shows me following errors.
OLE DB provider "SQLNCLI11" for linked server "V5_27\SQL2005" returned message "Login timeout expired".
OLE DB provider "SQLNCLI11" for linked server "V5_27\SQL2005" returned message "A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.".
Msg 10049, Level 16, State 1, Line 22
TCP Provider: The requested address is not valid in its context.
User and Password are not wrong.
Allow remote is enabled in both servers.
TCP/IP and Named Pipes are enabled in both servers.
Please help me, thanks!
Thanks everyone, I found a solution for my problem.
You can check the solution link here or do below steps.
Try to create a linkServer , Object Explorer -> Server Objects -> Linked Servers (Right click and create new)
Configure Settings
Enter your Server Name
Login with sa and password
Then Test Connection of it.
Enjoy your query.
select
lc.t2 as 'Local Stock Code',
ext.t2 as 'External Stock Code'
from
Stk001 lc,
[V5_27\SQL2005].[TESTACC].[dbo].[STK001] ext

Creating a view from another Server error

Hi All I am trying to create a View from another database server...
I have have got server A an din Server A is where i want to create a view referencing a table from Server B.... when I run the command below:
create view TableFromServerB as select * from ServerB.master.information_schema.table;
I get the following error:
OLE DB provider "SQLNCLI11" for linked server "ServerB" returned
message "Login timeout expired". OLE DB provider "SQLNCLI11" for
linked server "ServerB" returned message "A network-related or
instance-specific error has occurred while establishing a connection
to SQL Server. Server is not found or not accessible. Check if
instance name is correct and if SQL Server is configured to allow
remote connections. For more information see SQL Server Books
Online.". Msg 53, Level 16, State 1, Line 0 Named Pipes Provider:
Could not open a connection to SQL Server [53].
I have done some research online and i came to a source that suggested using sp_addlinkedserver in my command .. which i have done and when i did this it said server already exists . So is there anything i am missing out here??
I have seen an issue like this before:
Can you please do something like this:
Create a view in your linked server to access the object i.e master.information_schema.table;
Use this view in the queries from the server where you want to display the results.
Eg:
--- create view script--
create view dbo.vINFORMATION_SCHEMATABLES
as
SELECT *
FROM INFORMATION_SCHEMA.TABLES
go
-- select statement from local server
select * from [testSRV].[testDB_far].[dbo].[vINFORMATION_SCHEMATABLES]
Let me know if this helps.

"Could not Find Server in sys.servers" when deleting, but OK when selecting

We're currently having an issue with one of our linked servers.
if I run this code it works
SELECT *
FROM [LINKEDSERVER].[databasename].dbo.[tablename] a
INNER JOIN [localdb].dbo.[localtable] b
on b.somefield = a.somefield
But this fails
DELETE FROM a
FROM [LINKEDSERVER].[databasename].dbo.[tablename] a
INNER JOIN [localdb].dbo.[localtable] b
on b.somefield = a.somefield
giving error:
OLE DB provider "SQLNCLI10" for linked server <servername> returned message "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.".
Msg 7202, Level 11, State 2, Line 1
Could not find server <servername> in sys.servers. Verify that the correct server name was specified. If necessary, execute the stored procedure sp_addlinkedserver to add the server to sys.servers.
The linked server does appear in sys.sysservers, and I've tried dropping and readding the linked server, to no effect:
exec sp_dropserver <servername>, droplogins
exec sp_addserver <servername>
exec sp_serveroption <servername>, 'data access' , 'true'
Linked server is SQL 2005, linking server is 2008R2
In case this is relevant (and it seems possible), I recently migrated the SQL server to which we're linking to new hardware (with new SQL install etc.) and changed the IP of new hardware server back to that of old server for continuity. In all other respects this has worked fine. We never had this problem on the old server.

Linking Server in SQL Server 2008 R2

Can anyone guide me around to linking a server to another in SQL Server 2008 R2? I am getting the following error when trying to do so in Management Studio.
The linked server has been created but
failed a connection test. Do you want
to keep the linked server?
ADDITIONAL INFORMATION:
An exception occurred while executing
a Transact-SQL statement or batch.
(Microsoft.SqlServer.ConnectionInfo)
The OLE DB provider "SQLNCLI" for
linked server "CDSPM1" reported an
error. Authentication failed. Cannot
initialize the data source object of
OLE DB provider "SQLNCLI" for linked
server "CDSPM1". OLE DB provider
"SQLNCLI" for linked server "CDSPM1"
returned message "Invalid
authorization specification".
(Microsoft SQL Server, Error: 7399)
Seems like Authentication problem.
Test by creating the linked Server using "Server Type" as "Sql Server". Then go into "Security" and set your user mapping. As a test, create a SQL login on the remote system and specify that on the "Be made using this security context"
Be sure that you can PING the "Linked Server" name first. HTH
Use drop down and choose
SQL Server Native Client
instead of
SQL Server
Use below link to view the screenshots of connecting the linked server with SQL Server
To solve "Cannot initialize the data source object of OLE DB provider "SQLNCLI10" for linked server" problem
Connect MS Access to SQL server 2008 via linked server
Then use below query to get more information about the linked server
select * from openquery("owner_pc\sqlserver2008",'select * from Testing.dbo.test')
This was driving me round the bend. And the fact you can't edit a Linked server after you entered it is just bananas.
Anyway, just leave most of the boxes empty on the linked server dialogue! Use "SQL Server Native Client" like #abatishchev mentioned then..
Check Kamran's article here for the settings. Only Datasource was filled in for me as IP hostname, after I'd give the server a friendly name in "Linked server", and on the second tab didn't need to bother with any logins just radio button the bottom one and used the SA login on the remote box.
In the general page of New Linked Server, type the sql-server instance name in the [Linked Server] box. Click on the [SQL Server] check box when selecting [Server Type]. Type remote username and password atfer selecting [Be made using this security context] of Security tab.
Select top 10 * from [LINKEDSERVERNAME].[DATABASENAME].[SCHEMANAME].[TABLENAME]
Best of luck.
for more details information http://msdn.microsoft.com/en-us/library/ff772782.aspx
A possible cause, if you have clustered service , and has recently been balanced , it is likely that a connection has been blocked pointing to old resource.
Try moving again resource to another node and reopening the Management studio, try again linked server connection.

SQL Native Client, linked server error Only on Deletes

We are using a SQL Native Client to connect to a local SQL Server 2005 from a Borland application. It will fine for selects, inserts, and updates. When we delete we get the error:
Could not find server
SERVERNAME\SQLEXPRESS in
sys.servers. Verify that the correct
server name was specified. If
necessary, execute the stored
procedure sp_addlinkedserver to add
the server to sys.servers
The default instance, the only instance, is SERVERNAME\SQLEXPRESS, and we are not using linked servers. Any ideas? I believe we moved the MDF and LDF files to a new server for this DB, and then reattached it.
Update 1
There is no SQL. This is all happening through programmatic interaction with cursors. It is an ODBC driver using ADO. You run TableObj->Delete to remove the record.
Got it. I ran
SELECT ##servername
That returned the old host name of the box. I than ran
sp_dropserver 'OLDHOSTNAME\SQLEXPRESS'
go
sp_addserver 'NEWHOSTNAME\SQLEXPRESS', local
I then got
Server 'NEWHOSTNAME\SQLEXPRESS' is not
configured for DATA ACCESS
I ran
sp_serveroption 'ICS-POS3-NEW\SQLEXPRESS', 'data access' , 'true'
This got me the error
Transaction context in use by another
session
Which is because of linked servers. I found that the local option on the add server did not take affect until I restarted the server. I restarted, then it just worked.

Resources