I've been trying to create a linked server in SQL Server that accesses a
remote Index Service catalog, but I can't seem to do it. Let's call
the remote server "remoteServer" and the Catalog "remoteCatalog"
I've tried this:
EXEC sp_addlinkedserver remoteIndexServer, 'Index Server', 'MSIDXS',
'query://remoteServer/remoteCatalog'
and then i did run the SQL
SELECT * FROM OPENQUERY(remoteIndexServer,'select filename from scope()') AS Q
But i got the error as
OLE DB provider "MSIDXS" for linked server "remoteIndexServer" returned message "Service is not running. ".
Msg 7320, Level 16, State 2, Line 3
Cannot execute the query "select filename from scope()" against OLE DB provider "MSIDXS" for linked server "remoteIndexServer".
I have experienced this issue before. This is from memory so excuse any errors but if I recall correctly you will need to do the following.
Install the indexing service on your local SQL Server (this is so the provider is available).
Add a linked server to this LOCAL indexing service.
You can then run you query as below
SELECT *
FROM OPENQUERY(
LocalLinkedServer,
'select filename from RemoteServer.CatalogName..scope()'
) AS Q
If that doesn't work let me know, there is a post somewhere that describes how to do this. I can look it up if necessary but I think the above is right.
Related
I have an Oracle 11g XE database that I would like to transfer into SQL Server Express 2005.
At first I thought I'd just generate the tables in Oracle as SQL, manipulate the data formats, and run the query in SQL Server. This worked for small tables, but I have several tables with a few hundred thousands rows and some with millions of rows, so this solution won't work.
I then created a TNS file with the following content:
OracleTnsName =
(
DESCRIPTION=
(
ADDRESS = (PROTOCOL=TCP)(HOST=localhost)(PORT=1521)
)
(
CONNECT_DATA = (SERVICE_NAME=XE)
)
)
I followed instructions I found elsewhere on how to generate the ODBC connection, and the 'test connection' was successful.
I then ran these commands to create a Linked Server in MS SQL:
EXEC sp_addlinkedserver
#server = 'OracleLinkServer'
,#srvproduct = 'OracleTnsName'
,#provider = 'MSDASQL'
,#datasrc = 'OracleTnsName'
EXEC sp_addlinkedsrvlogin
#rmtsrvname = 'OracleLinkServer'
,#useself = 'False'
,#locallogin = NULL
,#rmtuser = 'user'
,#rmtpassword = 'password'
Now I'm trying to query a table in the Oracle database from SQL Server using openquery:
select * from openquery(OracleLinkServer, 'select * from oracleTable')
But get an error:
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "MSDASQL" for
linked server "OracleLinkServer" reported an error. The provider did
not give any information about the error.
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider
"MSDASQL" for linked server "OracleLinkServer".
When I check the properties of the Linked Server, and just click the OK, I get this error:
TITLE: Microsoft SQL Server Management Studio Express
"The linked server has been updated but failed a connection test. Do you want to edit the linked server properties?"
ADDITIONAL INFORMATION:
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.Express.ConnectionInfo)
The OLE DB provider "MSDASQL" for linked server "OracleLinkServer" reported an error. The provider did not give any information about the error.
Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "OracleLinkServer". (Microsoft SQL Server, Error: 7399)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=09.00.5000&EvtSrc=MSSQLServer&EvtID=7399&LinkId=20476
BUTTONS:
&Yes
&No
Please help!
Thanks
If you have successfully added your linked server, you no longer need OPENQUERY. You can just include the linked server name as the first part of the qualified name like so:
SELECT * FROM OracleLinkServer.database.schema.table
Not sure which parts you need, but the dots are key. Try this first:
SELECT * FROM OracleLinkServer...oracleTable
select *
from [server]..[xxx].[yyyyy]
It works for me.
Change
,#provider = 'MSDASQL'
with
,#provider = 'MSDAORA'
This question already has an answer here:
SQL Server Linked Server to Microsoft Access
(1 answer)
Closed 2 years ago.
I've set up a linked server to read a set of CSV files located locally on the SQL Server machine, as follows:
USE master
go
IF EXISTS (SELECT * FROM sys.servers WHERE name = 'MyLink')
EXEC sp_dropserver 'MyLink', 'droplogins';
EXEC sp_AddLinkedServer #server = 'MyLink',
#srvproduct = '',
#provider = 'Microsoft.ACE.OLEDB.12.0',
#datasrc = 'C:\Data\Feeds',
#provstr = 'Text'
EXEC sp_AddLinkedSrvLogin MyLink, FALSE
go
The following code then works perfectly, provided I'm logged in as 'sa' (either syntax works):
SELECT * FROM MyLink...myFile#csv
SELECT * FROM OPENQUERY(MyLink,'select * from myFile.csv')
If I log in as any other user, however, I get the following error:
Msg 7416, Level 16, State 2, Line 1
Access to the remote server is denied because no login-mapping exists.
Trying to change the remote login, either via script, or by modifying the linked server properties in SSMS to add a mapping, not only doesn't work but also breaks the ability of 'sa' to run the select statements.
BTW, I'm trying to work around a known bug in SSIS where it cannot handle CSV with commas inside double-quote-delimited fields. I stumbled across this post which describes using a linked server to get around the problem without having to code a custom parsing routine. Works great, except for the whole security thing; I don't want my application connecting as 'sa'. I'm using SQL 2005 SP3.
Any ideas on getting this to work with a run-of-the-mill login?
TIA,
Jim
#JustinStolle When I set it up as you describe, I get a different error for the non-sa user (sa still seems to work):
OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "MyLink" returned message "Cannot start your application. The workgroup information file is missing or opened exclusively by another user.".
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "MyLink" reported an error. Authentication failed.
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 "MyLink".
I can't import the file; SSIS can't handle it.
Just from doing a little testing, it seems only users in the sysadmin role can query this type of linked server since it needs permissions to work with the file system. There is probably a more thorough explanation elsewhere of which exact permissions are needed.
It seems to work when, within the linked server's security settings, I map a user with no special permissions to the local sa user or another sysadmin user (despite it being labeled "Remote User").
For a long-term solution, why not create a job that imports the CSV file to a local table? It would make maintaining permissions simpler and you'd have a defined table structure against which to write queries.
Hey all, the following select statement used to correctly query an Excel spreadsheet on a 64bit SQL Server 2008 R2, and now provides me with an error.
SELECT
MPNCode, Supplier, Stock , Price, Manufacturer, [Description]
FROM
OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0 Xml;Database=C:\inetpub\wwwroot\nCompass\Products\Import\SupplierProducts.xls;HDR=YES',
'SELECT * FROM [Sheet1$]') WHERE MPNCode IS NOT NULL
The error I get is.
OLE DB provider "Microsoft.ACE.OLEDB.12.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.ACE.OLEDB.12.0" for linked
server "(null)".
I've tried restarting everything and googled the thing to death - somehow something has happened that is preventing this from working.
The file-path/file-name is correct because when I change the path I get a different error message.
Ad-hoc connections are enabled from the surface manager - after this I'm stumped at what the issue could be.
Any help will be very much appreciated.
Is the linked spreadsheet opened on the desktop? What happens if you create a new sheet in the same folder and try to open it instead?
I think SQL Server needs to access to TEMP folders to copy or create some files.
If the folder does not exist or ther SQL Service account does not have enough permission to access the folders, you'll get the exception.
Run Procmon.exe on the server and execute the query again. You can see what's happening and where the SQL Server wants to access.
I'm trying to create a linked server in Sql server 2008 R2, just tried downloading the '64-bit version of the Office 2010 Access AD Engine' exe from Microsoft.
Unfortunately, I had tried adding a linked server, BEFORE making this installation, and it failed:
EXEC sp_addlinkedserver 'LinkedServer1', 'Excel', 'Microsoft.Jet.OLEDB.4.0', 'D:\Folder\Excel1.xls', '', 'Excel 8.0', ''
(let me know if this way of adding is not correct if you have another way to do it !)
After making the download, it gave a message that this server already exists :
"There are still remote logins or linked logins for the server 'LinkedServer1'."
Tried adding 'LinkedServer2' in the same way AFTER the download (used Excel5.0 as the parameter instead of Excel8.0). It works!
However, this old linked server seems to still exist, though I've tried dropping it:
To be sure it's actually there, I wrote this:
select * from sys.servers where is_linked =1
and the properties in detail:
server_id: 1
name= LinkedServer1
product= Excel
provider = Microsoft.Jet.OLEDB.4.0
data_source= D:\Folder\Excel1.xls
location:NULL
provider_string: Excel 8.0
is_linked=1
is_data_access_enabled=1
modify_date= 2010-08-15 19:56:02.307
Let me know if you notice me doing something wrong! I tried dropping 'LinkedServer2', it works! However, even when I'm trying to drop the same linked server1 like this:
Exec sp_dropserver #server = 'LinkedServer1'
fails on me, same message!
"There are still remote logins or linked logins for the server 'LinkedServer1'."
Tried adding a linked server using provider string as 'Excel 5.0' and it was added and dropped successfully.
Another Update:
This is failing again:
EXEC(' INSERT INTO Table1
SELECT col1, excel2col, excel3col, Replace(Replace(excel4col, ''"'', '''')
FROM OPENROWSET(''Microsoft.Jet.OLEDB.4.0'',''Excel 5.0;HDR=Yes;Database='+'D:\Folder\Excel1.xls'', [Sheet2$])')
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.
I have changed configuration to :
EXEC sp_configure 'Ad Hoc Distributed Queries', 1;
GO
RECONFIGURE;
Looks like a 64-bit/Sql Server R2 issue:
to delete a linked server explicitly , we should use:
sp_dropserver 'LinkedServer1', 'droplogins';
This solves the problem of an invalid linked server.
however, the Microsoft.jet.OLEDB.4 is not working, the same error keeps coming up:
<Errors> <Error>ERROR CAUGHT: 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.</Error> </Errors>
Tried downloading the Microsoft.ACE.OLEDB.12.0 and used this to add the linked server.
However, when I try to do an insert into table using OpenRowSet, a new error comes up:
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" reported an error. Access denied.
Msg 7301, Level 16, State 2, Line 1
Cannot obtain the required interface ("IID_IDBCreateCommand") from OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)".
Anyone faced this before, or knows how to solve this?
I am currently running a third-party software suite, which uses SQL Server as its database. I have a second instance of SQL Server running in a different location, and some apps that I am building in that instance SQL Server needs to access some data in the third-party software. So, I created an ODBC connection between the boxes, and set up the third-party SQL server as a linked server on my version of SQL Server. As a test, I ran something like the following statement from my SQL server, accessing one of the third-party's tables:
SELECT * FROM LinkedServerName.SchemaName.dbo.TableName
To which I recieved this error:
OLE DB error trace [Non-interface error: Column 'TableRowVersion' (compile-time
ordinal 4) of object '"SchemaName"."dbo"."TableName"' was reported to have a
DBCOLUMNFLAGS_ISROWVER of 0 at compile time and 512 at run time].
Msg 7356, Level 16, State 1, Line 1
OLE DB provider 'MSDASQL' supplied inconsistent metadata for a column. Metadata
information was changed at execution time.
This error is the same for any other table I try to access. What does this error mean, and is there a way around it?
I've had this happen a few times. The one workaround I found was to use OPENQUERY.
SELECT * FROM OPENQUERY(LinkedServerName, 'SELECT * FROM DBName.Schema.Table')
Also, the select you posted above has an incorrect 4 part name (could just be a typo but I wasn't sure). It should be LinkedServerName.DBName.SchemaName.TableName
Server: Msg 7356, Level 16, State 1, Line 1
OLE DB provider 'MSDASQL' supplied inconsistent metadata for a column.
Metadata information was changed at execution time.
If you use a four-part name syntax to query the data from the linked server database, you may receive this error message. To work around this problem, you can use the OPENQUERY syntax to query the data from the linked server database. You can turn on trace flag 7300 to receive more detailed information about this error message. To turn on trace flag 7300, run the following Transact-SQL statement:
DBCC TRACEON(7300)
I solved this with these steps:
1) Step 1:
• In SQL Server Management Studio open Linked Servers and then 'New Linked Server'.
• Inside of appeared wizard – Select the General tab.
• Specify alias name in "Linked server" field.
• Select SQL Native Client as provider.
• Add sql_server in "Product Name" field (that's the magic).
• In Data Source – specify name of the host to be used as linked server.
2) Step 2:
• In Security tab – specify proper security options (e.g. security context)
3) Step 3:
• In Server Options tab – put "Data Access", RPC, "Rpc Out" and "Use Remote Collation" to be true.
4) Step 4:
• Enjoy.
http://alexpinsker.blogspot.com.br/2007/08/how-to-give-alias-to-sql-linked-server.html