I am trying to link a remote server using the following commands:
EXEC sp_addlinkedserver
#server='REMOTESERVER', #srvproduct='',#provider='SQLNCLI'
EXEC sp_addlinkedsrvlogin
#useself='FALSE', #rmtsrvname='REMOTESERVER',
#rmtuser='user', #rmtpassword='pwd'
sp_testlinkedserver REMOTESERVER;
Where REMOTESERVER is the value returned on the remote server when I execute SELECT ##Servername
All command execute successfully. However when I view the catalog for my 'linked' server (in SSMS) it is listing the tables in the local server, not the remote. Equally if I run a query
SELECT * FROM [REMOTESERVER].localdb.dbo.localtablename;
It will return a results set from the local server.
Note I have confirmed that remote access is enabled as recommended in https://blogs.msdn.microsoft.com/walzenbach/2010/04/14/how-to-enable-remote-connections-in-sql-server-2008/
Any ideas? Thanks in advance.
Solved this by adding the remote IP address to the sp_addlinkedserver command:
sp_addlinkedserver
#server = N'REMOTESERVER',
#srvproduct=N'SQLNCLI',
#provider=N'SQLNCLI',
#datasrc=N'99.99.99.99'
Related
I trying to create a linkedServer over sql management studio and a cosmos db.
I already created the system data source and the test is fine:
But after create the linkedServer when i trying to open this error appears :
I'm creating the linke server with the following command :
USE [master]
GO
EXEC master.dbo.sp_addlinkedserver #server = N'DEMOCOSMOS', #srvproduct=N'', #provider=N'MSDASQL', #datasrc=N'CosmosDev'
EXEC master.dbo.sp_addlinkedsrvlogin #rmtsrvname=N'DEMOCOSMOS', #useself=N'False', #locallogin=NULL, #rmtuser=NULL, #rmtpassword=NULL
GO
I am connecting to Azure from SQL Server.
Task: Exporting Azure SQL Database data using bcp from SQL Server 2008 R2.
Step 1: Added IP Address in firewall settings in Azure.
Step 2: Running following script from SQL Server 2008 R2:
EXEC sp_configure N'show advanced options', 1
RECONFIGURE WITH OVERRIDE;
EXEC sp_configure N'xp_cmdshell', 1
RECONFIGURE WITH OVERRIDE;
DECLARE #SQL NVARCHAR(MAX) = ''
SET #SQL = N'Execute xp_cmdshell ''bcp "SELECT * FROM Table;" queryout "D:\AzureTableData.txt" -c -t#_# -S azure.database.windows.net -d DatabaseName -U user1#azure.database.windows.net -P *****"''';
NOTE: IP address is not static at my system and because of this reason, I keep getting an error:
Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]Cannot open server 'azurserver' requested by the login. Client with IP address 'XXX.XXX.XXX.XX' is not allowed to access the server. To enable access, use the Windows Azure Management Portal or run sp_set_firewall_rule on the master database to create a firewall rule for this IP address or address range. It may take up to five minutes for this change to take effect.
I can't configure firewall settings every time at Azure Portal.
You mean that Add client IP doesn't work for you, do you?
If you want to connect to the Azure SQL database for one time, you can set the firewall IP range from 0.0.0.0 to 255.255.255.255.
But for security reasons, we don't suggest to do that.
Azure SQL database could not set the dynamic IP firewall for now.
Hope this helps.
I Have a password-protected access database (.mdb) and sql server 2008 running in windows server 2008 R2 x64.
I installed "Microsost Access Database Engine" and I want to create a linked server to access, but I get this error:
"Cannot start your application. The workgroup information file is missing or opened exclusively by another user".
there is not any *.mdw file on my server.
I'm able to add a linked server to an unprotected database, but not to a protected database.
How can I add a mdw file without install MS access?
or is there any oher way to add a linked server?
USE THIS:
EXEC master.dbo.sp_addlinkedserver #server = N'Access', #srvproduct=N'Access', #provider=N'Microsoft.Jet.OLEDB.4.0',
#datasrc=N'C:\Program Files\ZKTime5.0\att2000.mdb'
EXEC master.dbo.sp_addlinkedsrvlogin #rmtsrvname=N'Access',#useself=N'False',#locallogin=NULL,#rmtuser=N'Admin',#rmtpassword=''
this works for me.
I am okay with the SQL script for creating linked servers:
////////////////Create linked server with no password access file
EXEC master.dbo.sp_addlinkedserver #server = N'linkedserver', #srvproduct=N'Smarthr', #provider=N'Microsoft.ACE.OLEDB.12.0', #datasrc=N'dbpath\file.mdb'
EXEC master.dbo.sp_addlinkedsrvlogin #rmtsrvname=N'LINKEDSVR',#useself=N'False',#locallogin=NULL,#rmtuser=NULL,#rmtpassword=NULL
//////////////////////////Create linked server with access password file
exec sp_addlinkedserver
#server = 'LinkServer',
#provider = 'Microsoft.ACE.OLEDB.12.0',
#srvproduct = 'Access4',
#datasrc = 'dbpath\filename.mdb',
#provstr = ';PWD=yourpassword'
exec sp_addlinkedsrvlogin
#rmtsrvname = 'LinkServer',
#useself = 'FALSE',
#locallogin = null,
#rmtuser = 'Admin',
#rmtpassword = null
I have created a stored procedure in sql server 2005 to export data from a query to a network path. The user is a sql user and it is also created in the AD. The server that I am logged in is a remote server, with sysadmin privilege. I am encountering the following error while executing the procedure or even the query:
output
SQLState = 08001, NativeError = 53
Error = [Microsoft][SQL Native Client]Named Pipes Provider: Could not open a connection to SQL Server [53].
SQLState = 08001, NativeError = 53
Error = [Microsoft][SQL Native Client]An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections.
SQLState = S1T00, NativeError = 0
Error = [Microsoft][SQL Native Client]Login timeout expired
NULL
It looks like I have no access to the remote server, while I am executing the query while I am logged in the server. The procedure also executes automatically at 01.30 am. The command that is executed is a bcp command :
DECLARE #SQLCommand [varchar](max)
,#Query [varchar](max)
,#SERVER VARCHAR(1000)
SET #Query = 'SELECT * FROM INFINITY_SYSTEM.[dbo].[CTI_WFM_LILO_View]'
SET #SERVER = '[server_name]'
SET #SQLCommand = 'EXEC xp_cmdshell ''bcp "' + #Query + '" queryout "\\network_path\lilo'+CONVERT(VARCHAR,GETDATE(),112)+'.csv" -Uusername -Ppassword -c -t, -r, -S"'+#SERVER+'"''' --also tried with -T in stand of the -Uusername -Ppassword
EXEC (#SQLCommand)
The command works when I try it from a local DB in my local sqlserver to the same path.
Thanks
Make sure that you can telnet to the remote server. I would also try to connect to the remote server via sqlcmd. You may have a firewall blocking the connection. Also the sql server services will need permissions to the share/directory, in order for you to write a file to it.
Another thing you should consider is using an SSIS package to export the data to the remote share. Generally is not a great practice to use xp_cmdshell to export the data. You can do everything you are trying to do via a simple SSIS package. As an added benefit this also minimizes security risk because you can disable xp_cmdshell.
I would like to make a copy of what's on my remote server at xxx.safesecureweb.com.
How do I connect to it from my local SQL Server?
Is the syntax something like:
sp_addlinkedserver
#server='PRODUCTION',
#provider='xxx.safesecureweb.com',
#Username='myUsername',
#Password='myPassword'
What I'm thinking of doing is writing a bunch of insert statements like:
INSERT INTO Test.Table
SELECT * FROM Production.Table
You do not specify the remote user and password in the linked server definition. Linked servers have a separate object that mapps the login of users connected to the local server (the 'locallogin') with remote logins. See Security for Linked Servers. For example, the following maps all local logins on the linked server to the specified MyUserName SQL Login:
exec sp_addlinkedserver 'xxx.safesecureweb.com';
exec sp_addlinkedsrvlogin 'xxx.safesecureweb.com'
, 'FALSE', NULL, 'myUserName', 'myPassword';
You can only map with user/password a remote SQL login. Remote Windows logins (trusted authentication) must use integrated authentication and configure the server for constrained delegation.
Provider should be the client provider you want to use to connect. #datasrc is the servername to connect to.
sp_addlinkedserver
#server='PRODUCTION',
#provider='SQLNCLI', -- sql native client.
#Username='myUsername',
#Password='myPassword',
#dataSrc = 'xxx.safesecureweb.com'
Then, when querying, I believe you need to use a four part name fot the table:
INSERT INTO Test.Table
SELECT * FROM Production.mydatabase.dbo.Table
http://msdn.microsoft.com/en-us/library/ms190479.aspx