SQL Server OpenQuery to Oracle schema with $ - sql-server

I am trying to connect from SQL Server 2008 R2 into an Oracle Linked Server, but the Oracle Schema has a $ symbol in it. Unfortunately, I can't change the schema name, but it appears to be causing me an issue when trying to extract information using OpenQuery. Is it possible to escape this character?
select *
FROM OPENQUERY(linksrv, 'SELECT * FROM [ABC$SCHEMA].[TABLE] where [ID] = ''ABCD0001'' ') oq
The above gives me an error message as follows:
OLE DB provider "OraOLEDB.Oracle" for linked server "linksrv" returned message "ORA-00903: invalid table name".
The below query works, but it is painfully slow on something that takes half a second to run on the Oracle database so I am hoping OPENQUERY might give me results slightly faster?
SELECT *
FROM [linksrv]..[ABC$SCHEMA].[TABLE]
where [ID] = 'ABCD0001'
GO
Version information:
Microsoft SQL Server Management Studio 10.50.2500.0
Microsoft Analysis Services Client Tools 10.50.2500.0
Microsoft Data Access Components (MDAC) 6.1.7601.17514
Microsoft MSXML 3.0 6.0
Microsoft Internet Explorer 9.0.8112.16421
Microsoft .NET Framework 2.0.50727.5456
Operating System 6.1.7601
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
Any assistance would be greatly appreciated!!
Thanks in advance!!

Based on the comments it appears that the syntax should be different for Oracle, where square brackets actually cause problems rather than prevent them:
SELECT *
FROM OPENQUERY(linksrv, 'SELECT * FROM ABC$SCHEMA.TABLE ...') AS oq;

Related

Error inserting in Microsoft Access 2002-2003 "long Text" field SQL Server 2019 linked Server Microsoft Access Database Engine 2010 x64

I am attempting to migrate a number of stored procedures, which insert to Microsoft Access 2002-2003 format database files, as linked servers.
The process is currently working fine on the following configuration
Windows Server 2008 R2 Standard
SQL Server 2014
Microsoft Access Database Engine 2010 x64 - v14.0.7015.1000
The updated configuration is as follows
Windows Server 2019 Datacenter
SQL Server 2019
Microsoft Access Database Engine 2010 x64 - v14.0.7015.1000
The Microsoft.ACE.OLEDB.12.0 has registered fine on the newer server configuration, and is available as a linked server "provider"
The SP inserts to a number of tables, with varying data types, and all are successful, with the exception of fields where the SQL Server field is of type nvarchar and the Access mdb field is of type "Long Text", where I get the error.
Msg 7344, Level 16, State 1, Line 182
The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "[Access mdb Linked Server Name]" could not INSERT INTO table "[Access mdb as Linked Server]...[Table Name]" because of column "[Column Name]". The column had a bad status.
The Long text fields in the Access mdb are reported/displayed as varchar data type, in the linked server configuration.
I have tried writing simple, short, strings to the field, CASTing as varchar data type, but still get the same error.
I've done lots of googling, but can find no examples of others experiencing similar issues.
I suspect it is a compatibility issue, between the SQL server version and access database engine but, again, have been unable to find any useful resource.
Has anyone experienced a similar issue, and found a resolution?
Or if you can direct me to a suitable resource where I can find more info.
I managed to resolve this, with changes to the configuration of the OLEDB provider on the SQL server.
It was necessary to enable both:
Dynamic Parameter
and
Allow inprocess
in the provider Options

Restoring Database SQL Server - data is null this method or property cannot be called on null values

I am trying to copy 2 databases from SQL Server 2012 to a new VM SQL Server 2017.
One of the databases was restored successfully but the other is giving me the below issues.
Databases both restored successfully, however 1 of the databases when I try to access the tables I am getting this error in SSMS "data is null this method or property cannot be called on null values"
Appreciate any help.
SQL Server 2017 has numerous features that aren't present in SQL Server 2012 and it is likely your version of SSMS doesn't support the newer version of SQL Server.
It's probable that when you open the database in SSMS it is trying to load Database Diagrams (now deprecated).
Are you able to run:
USE [databasename]
GO
SELECT * FROM sys.objects
and see if your expected tables are in there?

How to migrate a database that uses master db stored procedures to Azure?

We have a sql2k8 database that uses sp_xml_preparedocument, a master db system extended stored procedure, that needs to go to Azure. The migration tools (SSMS2016 wizard) give a validation error: SQL71501 that [dbo].[sp_xml_preparedocument] is a missing reference, when validating the export.
I can't see any way to reference the sp so it can be migrated. Intellisense always shows an error too.
Could you first verify that your code works fine on Azure SQL when you manually execute the scripts? When I execute queries with sp_xml_preparedocument from MSDN on my Azure SQL Database it works fine.
If your code works, then it is a problem in SSMS migration assistant, so in that case you should report bug on SQL Server Connect site, with some minimized repro script, so SQL Server team can fix it.
Use SQL Server 2016 Enterprise with Service Pack 1 (x64) . The SP1 should support Azure DB . The 2012 version of Sql server might do iT.

SQL Server with Oracle SQL Developer 4.1 - can't view tables

I cannot seem to browse the tables on my Azure SQL Server database from within Oracle SQL Developer (Version 4.1 - using jtds-1.3.1.jar plugin).
I can connect and perform all queries (inserts, selects, etc.), but when I try to expand it to view the tables, I see this error:
An error was encountered performing the requested operation:
Reference to database and/or server name in 'master..sysdatabases' is
not supported in this version of SQL Server.
Vendor code 40515
Note: I tried rolling SQL Server back to version 3, and I'm getting the same error.
Please advise. Thanks for your help!
We're not certified for Azure..there's a similar problem in SQL 2014. The way we're asking for a list of tables isn't valid in that version. Would require an enhancement request to support Azure for Oracle Database Migrations.

RODBC management of dates from SQL server

I have a SQL database (2012) that I am trying to access through R (R Studio). From Enterprise Manager this is what it looks like:
select top 5[date],value from dbo.history
1991-02-11 11.1591
1991-02-12 11.2
1991-02-13 11.3501
1991-02-14 11.37
1991-02-15 11.3002
However from R this is what I get:
sqlQuery(DF_CN,'select top 5 [date],value from dbo.history')
date value
1 0011-02-19 11.16
2 0012-02-19 11.20
3 0013-02-19 11.35
4 0014-02-19 11.37
5 0015-02-19 11.30
When I try and select all the data from the table, this is what I get
sqlQuery(DF_CN,'select * from dbo.history')
Error in charToDate(x) :
character string is not in a standard unambiguous format
It may to be something about the yyyy-mm-dd default format from SQL server which I can change if I use CONVERT, but this looks like a hack and the SELECT * would not work.
Is there something in R I can do to recognise the SQL Server dates?
Ben
This is driving me nuts - surely someone has seen this before - there is a clear disconnect between the SQL Server output and what R is reading.
I am using RStudio 0.98.1091 and R x64 3.1.2.
Sql Server 2014
Microsoft SQL Server Management Studio 12.0.2000.8
Microsoft Data Access Components (MDAC) 6.1.7601.17514
Microsoft MSXML 3.0 4.0 6.0
Microsoft Internet Explorer 9.10.9200.17148
Microsoft .NET Framework 4.0.30319.18444
Operating System 6.1.7601
ODBC Driver 11 for SQL Server.
Everything looks up to date on my system.
the [date] column was of type DATE, is now DATETIME. I now get this;
sqlQuery(DF_CN,('select * from dbo.history')
Error in as.POSIXlt.character(x, tz, ...) :
character string is not in a standard unambiguous format
It looks like some disconnect between SQL server setup and R setup.
I worked it out by using the as.is parameter:
sqlQuery(DF_CN,'select * from dbo.history',as.is=T)
Then casting the values I needed directly in R.
I have worked it out.
Driver set to SQL server Native Client 11.0
ODBC settings - Use regional settings when outputting currency, numbers, dates and times switched off.
I am thinking that SQL Server has its own ideas on regional settings rather than what has been provided by windows causing great confusion.

Resources