SQL Server 2008 linked server connection string setup - sql

I'm trying to setup a linked server to another instance of SQL Server installed on the same Windows Server. In the SQL Server Management Console I have both instances added and I'm trying to do a insert from one database into another. I setup the linked server using the query below and I'm getting the following failure message when I test the connection of the the linked server. Can someone help me solve this problem?
USE master
GO
-- To use named parameters:
EXEC sp_addlinkedserver
#server = 'Server Name', --actual server name
#srvproduct = '',
#provider = 'MSDASQL',
#provstr = 'DRIVER={SQL Server};SERVER=Database name;UID=test_user;PWD=test_pwd;'
GO
Error message
Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "Server Name".
OLE DB provider "MSDASQL" for linked server "Server Name" returned message "[Microsoft] [ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()).".
OLE DB provider "MSDASQL" for linked server "Server Name" returned message "[Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied.". (.Net SqlClient Data Provider)

exec sp_addlinkedserver #server='servername';
exec sp_addlinkedsrvlogin #rmtsrvname='servername',#useself=false, #rmtuser='sa', #rmtpassword='Password';
if sql server is a named instance then servername\instancename

Related

Access another SQL Server through stored procedure

I want to access another SQL Server to import and update data of that server's database through a stored procedure.
For that I created linked server using sp_addlinkedserver.
EXEC sp_addlinkedserver
#server = N'LINKEDSERVER'
,#srvproduct=N''
,#provider=N'SQLOLEDB'
,#datasrc=N'[DB-Instance.cuprxxxlj.ap-xxxxxxx-x.rds.amazonaws.com]';
Then try to access by SQL query
SELECT *
FROM [LINKEDSERVER].[DATABASE].[dbo].[TABLE]
And getting errors like
OLE DB provider "SQLNCLI11" for linked server "LINKEDSERVER" returned message "Login timeout expired".
OLE DB provider "SQLNCLI11" for linked server "LINKEDSERVER" 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 had created database instance on amazon server and another is also on the amazon server and both are publicly accessible but don't know why I'm getting Server is not found or not accessible. Am I missing any server site setting or something else?
Please guide me if I am going in wrong direction.
I found the answer. The problem was an instance, I had created "Amazon RDS for SQL Server" which is currently not supporting to "Linked servers".
So I create a new AWS EC2 instance for Windows Server 2012 R2 and then I create Linked servers in it and tried to assess remotely. Now its working fine as I wanted.
Here is detailed document to Running SQL Server Linked Servers on AWS
Thanks.
Maybe try changing the timeout settings?
sp_configure 'remote query timeout', 0
go
reconfigure with override
go
This article explains in detail how to link one AWS Sql Server to another (https://aws.amazon.com/blogs/apn/running-sql-server-linked-servers-on-aws/). I am not certain what is wrong in your case, but this has a lot of steps that I do not see in your description.
And the one thing that does jump out at me is that you haven't configured any login security/access control. So unless the target server is open to the world, I would guess that you have to add that as a minimum.

Cannot read Excel file from SQL Server with multiple versions of SQL Server

EXEC sp_configure 'show advanced options', 1
RECONFIGURE
GO
EXEC sp_configure 'ad hoc distributed queries', 1
RECONFIGURE
GO
USE [master]
GO
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 1
GO
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters', 1
GO
Reading Excel
DECLARE #SQLconnect VARCHAR(8000)
SET #SQLconnect = 'SELECT * FROM OPENROWSET(''Microsoft.ACE.OLEDB.12.0'',
''Excel 8.0;Database=D:\WAGES.xlsx;'',
''SELECT * FROM [Sheet2$]'')'
EXEC (#SQLconnect)
Exception
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" reported an error. The provider reported an unexpected catastrophic failure.
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)".
Sometimes it gives error sometimes it goes in infinite loop of execution.
NOTE: I am getting this error after installing SQL Server 2008 R2 over SQL Server 2012.
OS: Windows 7 32-bit
SQL Server 2008 R2 and SQL Server 2012 installed
The SQL Server Error Message if a user have no rights for SQL Server TEMP directory:
OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)"
returned message "Unspecified error".
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider
"Microsoft.Jet.OLEDB.4.0" for linked server "(null)".
Grant rigths to TEMP directory
(i.) This step is required only for 32-bit SQL Server with any OLE DB provider
The main problem is that an OLE DB provider creates a temporary file during the query in the SQL Server temp directory using credentials of a user who run the query.
The default directory for SQL Server is a default directory for SQL Server service account.
If SQL Server is run under Network Service account the temp directory is like:
C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp
If SQL Server is run under Local Service account the temp directory is like:
C:\Windows\ServiceProfiles\LocalService\AppData\Local\Temp
Microsoft recommends two ways for the solution:
A change of SQL Server TEMP directory and a grant of full rights for all users to this directory.
Grant of read/write rights to the current SQL Server TEMP directory.
See details: PRB: "Unspecified error" Error 7399 Using OPENROWSET Against Jet Database
Usually only few accounts are used for import operations. So we can just add rights for these accounts.
For example, icacls utility can be used for the rights setup:
icacls C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp /grant vs:(R,W)
For more information follow this Link
Try these settings
Open SQL Server Configuration Manager.
Select the SQL Server Services folder in the left pane.
Right-click the SQL Server (MSSQLSERVER) service in the right pane.
Click Properties.
Click the Advanced tab in the properties dialog that pops up.
Add “-g512;” to the front of the value for parameter “Startup Parameters”.
Click OK.

Creating a linked server in SQL Server 2012 for analysis services with the connection string consisting of the instance name

I was creating a linked server from SQL database to Analysis services using the server ip along with the instance name. While doing so I got the following error:
Cannot initialize the data source object of OLE DB provider "MSOLAP" for linked server "TEST".
OLE DB provider "MSOLAP" for linked server "TEST" returned message "Errors in the OLE DB provider. Could not connect to the redirector. Ensure that the SQLBrowser service is running on the '*****' server.".
OLE DB provider "MSOLAP" for linked server "TEST" returned message "Errors in the OLE DB provider. An error occurred while named instance information was being retrieved from the SQLBrowser service on the '*****' server.".
So I created an alias for the server along with the instance name. After doing so got the error below:
Cannot initialize the data source object of OLE DB provider "MSOLAP" for linked server "TEST".
OLE DB provider "MSOLAP" for linked server "TEST" returned message "The following system error occurred: The requested name is valid, but no data of the requested type was found. ".
The above issue existed due to an issue in the port no for the analysis services.
Kindly refer to the link below :
http://msdn.microsoft.com/en-us/library/ms174937.aspx
Following the steps mentioned in the above link I observed that the analysis services for the named instance was using a different port number. with "MSOLAP$InstanceName service" determined which port was being used. Using the linked server script created the linked server.
EXEC sp_addlinkedserver
#server = 'server',
#srvproduct = 'SSAS',
#provider = 'MSOLAP',
#datasrc = 'IPAddress:portnumber',
#catalog = 'catalog'

SQL to Access linked server

I am trying to add a linked server to a Access database. I am using the following SQL code to do this.
exec sp_addlinkedserver
#server = 'Test',
#provider = 'Microsoft.Jet.OLEDB.4.0',
#srvproduct = 'OLE DB Provider for Jet',
#datasrc = '\\srv\public$\CM Database\Data\sysConfig_dat.mdb'
go
EXEC sp_addlinkedsrvlogin Test, FALSE, Null, Admin, Null
but when i run this...
select * from Test...tblProduct
i get this error...
OLE DB provider
'Microsoft.Jet.OLEDB.4.0' cannot be
used for distributed queries because
the provider is configured to run in
single-threaded apartment mode. what
am i doing wrong?
I am using SQL Server Management Studio 2008 on a 32 bit system.
I figured it out...
The server running SQL Server is a 64Bit machine. The typical data connectivity component drivers did not work with this machine (ie the download that installs the Microsoft.Jet.OleDB.4.0 as a provider). I had to download the components for Access 2010 which has a 64Bit option.
Download from here
That installs the Microsoft.ACE.OLEDB.12.0 as a provider and I can use the SQL command that BradBenning mentioned in his post.
Try using the Microsoft ACE OLEDB provider:
EXEC sp_addlinkedserver
#server = 'Test'
,#provider = 'Microsoft.ACE.OLEDB.12.0'
,#datasrc = '\\srv\public$\CM Database\Data\sysConfig_dat.mdb'
,#srvproduct='Access'
GO

Linked server issue while migrating shards from SQL Server 2005 to 2008 Enterprise R1

I am facing a strange problem during data migration. We "restored" data from 3 shards(on diff SQL Server 2005 machines) to single SQL Server 2008. We have single 2008 server now but the shards are unchanged from 2005.
Now I am trying to exec a SP on Master but I get the following error
Creating SP
OLE DB provider "SQLNCLI10" for linked server "(null)" returned message "Login timeout expired".
OLE DB provider "SQLNCLI10" for linked server "(null)" 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].
All shards are on SQL Server. We are not using SQLNCLI10 provider. But it's strange to see this error.
My SP use some dynamically created distributed queries in SP.
eg. Shard01.dbo.Update.....
What could possible go wrong.
Solved the problem.
My SP was using a view which was moved restored from 2005 to 2008. 2008 has different shards configurations and SQLNCLI10 was used for OPENROWSET in 2005 but not in 2008 as all the DBs were on same server.
Redefining the view solved the issue.