Query database with period in name on a linked SQL Server - sql-server

I need to query a database on a linked server, and unfortunately the database name contains a period.
This fails;
select top 10 *
FROM [LINKED_SERVER].[DATABASE_NAME.1].dbo.[TABLE_NAME]
with this error:
OLE DB error trace [Non-interface error: OLE DB provider unable to process object, since the object has no columnsProviderName='SQLOLEDB', Query="DATABASE_NAME.1"."dbo"."TABLE_NAME"'].
Msg 7357, Level 16, State 2, Line 2
Could not process object '"DATABASE_NAME.1"."dbo"."TABLE_NAME"'. The OLE DB provider 'SQLOLEDB' indicates that the object has no columns.
Connecting to the same linked server without a period in the database name works;
select top 10 *
FROM [LINKED_SERVER].[DATABASE_NAME].dbo.[TABLE_NAME]
As there are many references to the existing database name out of my control, I hope to find a solution that avoids re-naming the database permanently.
I would like to be able to create a synonym or some other alias, or find some other way to get this working.

Periods in database names accessed via linked servers are perfectly acceptable when escaped with brackets [] - the error your getting must be something else.
I can confirm this on my test rig:
One thought, your using the old SQLOLEDB provider for your linked server, have you tried using SQLNCLI10 instead?

Avoid periods in identifiers,
e.g. in SSMS
sp_help [sales.order]
will not work, even with brackets

Related

SQL Server select from linked server throw error if user has "deny view definition"

I have users with datareader permission on my sql, the problem is that i noticed that the users are doing "fishing" query a lot (they don't know what exactly should be querying to get what thy need).
This is a production SQL and we started to have deadlock because of those users.
Trying to don't break their process i applied "deny view definition to [user]" so they cannot see the list of tables, view, stored procedure, so no more "fishing"
This was a great solution, it works perfect if you connect directly to the SQL Server, you can run queries (select) but you cannot see the list of tables.
However many users are using those account to connect to our SQL using linked server, and when the run a query using the linked server they are getting error:
SELECT TOP 100 *
FROM [SERVERSQL].[DATABASE].dbo.[TABLE]
Msg 7314, Level 16, State 1, Line 1
The OLE DB provider "SQLNCLI11" for linked server "SERVERSQL" does not contain the table ""[DATABASE]"."dbo"."[TABLE]"". The table either does not exist or the current user does not have permissions on that table.
Using SQL Server version 2014 (v12.0.2000.8) and 2016 (v13.0.5492.2).
What is the correct way to hide tables, view, stored procedures, etc but allow select and make it work on linked server?
Thanks
Linked server from one SQL Server to Another:
Linked server name is: PLWNSAVSQL02D which is SQL Server
This sql to linked server works:
select count(*) from [PLWNSAVSQL02D].[SFI_WMS].dbo.[TCOMPANYPALLETMESSAGES];

OpenQuery Update against MariaDB returning 'Table doesn't exist'

I have SQL Server 2008 SP4 instance accessing a linked server that is running a MediaWiki database on MariaDB (v 5.5.44). I am able to select from the table no problem:
SELECT *
FROM OPENQUERY(MEDIAWIKI,
'SELECT * FROM wiki.page WHERE page_title = ''Test''')
But when I try to update the table:
UPDATE OPENQUERY(MEDIAWIKI,
'SELECT * FROM wiki.page WHERE page_title = ''Test''')
SET page_title = 'TestChange'
I get the following error message:
OLE DB provider "MSDASQL" for linked server "MEDIAWIKI" returned message "Table 'def.page' doesn't exist".
Msg 7343, Level 16, State 4, Line 1
The OLE DB provider "MSDASQL" for linked server "MEDIAWIKI" could not UPDATE table "[MSDASQL]".
The user has full permissions, so that shouldn't be an issue. I'm also able to make updates against other linked servers running MySQL. Any help is hugely appreciated. Thanks!
EDIT: I am able to get around this by building a dynamic query string and executing it at the linked server, mostly just curious as to why this is happening at this point.
I second Vladislav here. 'def' is used as catalog value(if you look in columns metadata returned by server, or in INFORMATION_SCHEMA tables 'TABLES' or 'COLUMNS'. Both MySQL and MariaDB connectors return table's schema as catalog, and NULL as schema.
It must be that MariaDB Connector/ODBC has but and returns 'def' somewhere in metadata as schema(or catalog?). What version do you use? In fact it could be fixed in latest version. But please better proceed in the JIRA issue created by Vladislav
What kind of ODBC driver do you use? There are 2, MariaDB one, and MySQL one. This looks like a bug in one of these ODBC. Now what does "def" mean. There is a great amount of confusion in MySQL world about catalog, database and schema. MySQL result sets are returned with metadata (column info description). Column info contains several fields, among them "table catalog" (always hardcoded "def") , and also "table schema", aka database. Catalog does not have any meaning currently, and never had, but who knows maybe it could mean something in the future. "schema" on the other hand, is something that you can put into UPDATE command ( UPDATE schema.table SET field=value WHERE ...) . So the bugs seems to be is that one of the ODBC drivers incorrectly chooses "catalog" over "schema".

Error with linked server using Microsoft.Jet.OLEDB.4.0

I started at this company, and the jobs were pretty complex and undocumented.
One of the procs checks on txtfiles that SSIS creates by using a linked server that uses Microsoft.Jet.OLEDB.4.0 and points to its own C drive. Using that, the job does a count on each table, and compares it to its totals. Maybe unnecessarily complex.
It was working properly till last Friday, when I started getting the error:
OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "textserver"
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 "textserver".
The query used is:
SELECT COUNT(*) FROM textserver...[textfile#txt]
I've tried rebooting the server, and recreating the linked server to no avail.
Has anyone seen this issue before?
I've had similar problems in the past, but restarting the linked to server usually worked for me. A few things to try:
You may also want to verify the account running the SSIS package has rights to the linked server location on the C drive.
Also, make sure remote transactions are allowed.
Last suggestion would be to see if any MS updates or patches were installed since it last worked and try rolling them back.

Cannot connect to MS Access file from SQL Server 2008

I have been trying for the past week or so to import data programmatically to a SQL Server 2008 table from a Microsoft Access .mdb file. I have been getting nothing but errors, and solving one just reveals another. I made the file into a linked server, and now when I try to query it with:
Select * from OPENQUERY(Importdata, 'Select * from [IMBPieceBC]')
I get the error:
OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "Importdata" returned message "Cannot open database ''. It may not be a database that your application recognizes, or the file may be corrupt.".
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 "Importdata".
I've read several suggestions to relink dlls in the registry, but I've done that, and I'm still getting the error. Is there anything else I can do to fix it, or at least figure out what is wrong?
Migrating the data to a SQL Server instance is not an option. The mdb files are generated by a third-party program, so there's nothing we can do about it.
I have a similar situation at my workplace - a third party application that maintains data in MDBs, but other applications needing access to it. How I've done it is that this 'intermediary' application has links to the SQL Server tables and the MDB tables. You could use either a query or a VBA written form event to transfer information from the MDB table(s) involved into your corresponding SQL Server tables using a INSERT INTO query, fitted with a SELECT FROM subquery providing the values being inserted.

Linked SQL Server database giving "inconsistent metadata" error

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

Resources