I have created a linked-server definition according to the article at :
http://www.ideaexcursion.com/2009/01/05/connecting-to-oracle-from-sql-server/
My aim is to transfer rows to tables at Oracle 11gR2.
After creating linked server, whenever I try to select a table using a query like :
SELECT *
FROM [192.168.1.188]..[ESIPARIS].[T_ERROR_LOG]
I get the error below :
Msg 7356, Level 16, State 1, Line 1
The OLE DB provider "OraOLEDB.Oracle" for linked server "192.168.1.188"
supplied inconsistent metadata for a column. The column "EVENT_OBJECT"
(compile-time ordinal 2) of object ""ESIPARIS"."T_ERROR_LOG"" was reported
to have a "LENGTH" of 50 at compile time and 100 at run time.
One more thing is that it duplicates field names whenever a select statment is prepared by "Sql Server Management Studio", some fields are duplicated as below :
SELECT [EVENT_DATE]
,[EVENT_DATE]
,[EVENT_DATE]
,[EVENT_DATE]
,[EVENT_OBJECT]
,[EVENT_OBJECT]
,[EVENT_OBJECT]
,[EVENT_OBJECT]
,[MESSAGE]
,[MESSAGE]
,[MESSAGE]
,[MESSAGE]
,[EVENT_ID]
FROM [192.168.1.188]..[ESIPARIS].[T_ERROR_LOG]
I would be very happy to hear from you about any ideas, thank you for your concern,
Best Regards,
Kayhan YÜKSEL
There are a number of scenarios which might throw this error:
your distributed query in SQL Server references a view with an underlying table in Oracle with a primary key column created in a certain way, Find out more
there's a bug when the querying a view with numeric columns. Find out more
it may be a problem with driver incompatibility, such as using the MS OleDB driver instead of the one Oracle provides.
If it isn't the driver one possible workaround is to use OPENQUERY. Otherwise. this support note contains general information on troubleshooting linked server and Oracle.
(This problem is a fairly generic one, so it turned out that the actual resolution was none of the things I suggested. I'm incorporating #kayhanyüksel's solution in the body of this response for the sake of completeness.)
Solved it with changes at listener and tnsnames. We are now able to connect from SQL Server to Oracle 11gR2 (running on 64 bit Red Hat Enterprise Linux 5.4 ) and vice versa. Documents followed are
- Making a Connection from Oracle to SQL Server
- The Oracle Gateways documentation
I had the same problem: The column ...... was reported
to have a "LENGTH" of 50 at compile time and 100 at run time. and duplicate column names when selected.
while i was trying to run a query in MS SQL from an ORACLE 11g database
I used the follownig type of query and it worked !
DECLARE #TSQL varchar(8000)
SELECT #TSQL = 'SELECT * FROM OPENQUERY(MyLinkedServer,''SELECT * FROM TableName'')'
EXEC (#TSQL)
where MyLinkedServer is the name of the linked server and
TableName is the name of the table.
here you have the link to the article that helped me: http://support.microsoft.com/kb/314520
Old thread but it may be useful to someone.
When I recently encountered this error, using as provider the MS OleDB driver instead of the Oracle OleDB provider solved the problem.
I have the same issue with 11g client but it was disappeared with client version 12 which works for me is using OPENQUERY and to_char with the field that makes problem.
I confirm that SQL management studio (no matter what version) gives many duplicated field. The only installing of last driver version we can have consistent queries. I hope it can be useful for you!
Related
I have an instance running SQL Server 2014 Express Edition (64-bit Build 19044). I have the same machine running a MySQL server (innodb_version: 5.7.33, protocol version: 10, version_compile_machine: x86_64, version_compile_os: Win64), and I need to write some information in this MySQL Server through a SQL Server script (I need to connect multiple servers and I would like to center everything in this SQL Server. This MySQL server I'm talking about is one of them).
I've found many tutorials teaching to use linked servers, like the following: https://gunnarpeipman.com/mssql-mysql-linked-server/
I've configured the ODBC connection as a System DSN using both MySQL ODBC 8.0 Unicode Driver and ANSI Driver;
I could connect to the MySQL server, and list the tables in this server through SSMS's object explorer. Unfortunately, I spent A LOT of time trying to query data from this server, since I always get errors pointing as if I don't have enough permission to see columns from this table:
When trying to [right click table > Script table as > Select to > clipboard]
[DWGLUO].[dw_vtiger]..[dleads] contains no columns that can be selected or the current user does not have permissions on that object.
When trying to query some data with OPENQUERY:
SELECT * FROM OPENQUERY(DWGLUO_ANSI,'SELECT idlead FROM DWGLUO_ANSI.dw_vtiger..dleads')
Msg 7321, Level 16, State 2, Line 1
An error occurred while preparing the query "SELECT idlead FROM DWGLUO_ANSI.dw_vtiger..dleads" for execution against OLE DB provider "MSDASQL" for linked server "DWGLUO_ANSI".
I can see all tables, but i can't see any columns :(
Also, by running the query below, I managed to find the column names, so they're there somewhere:
EXEC ('SELECT TABLE_SCHEMA,
TABLE_NAME,
COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = ''dleads''') AT DWGLUO_ANSI ;
TABLE_SCHEMA
TABLE_NAME
COLUMN_NAME
dw_vtiger
dleads
idlead
dw_vtiger
dleads
nome
... (continues) ...
If someone could help me I would really appreciate it. Thank you all in advance.
In SSMS I'm connected to an Intersystems Cache database using ODBC driver and linked server When I fetch data using a SQL query like
SELECT Text FROM OPENQUERY([ODBC_CACHE_DB],'SELECT TOP 100 Text FROM cls.Actions')
IN SSMS it gives results but it gives ? for arabic characters like
"18:29:00 [Mohamad] ????? ??? ?? ??? ??? ?????? ????? ? 18:30:30 [Customer] Hi Sirius is jai"
how could get arabic texts ?
note: I can read and write arabic text with using nvarchar data type
Had a similar issue. My setup was a linked server setup between MSSQL 2012 cluster and Intersystems Cache 2009.x using MS OLE ODBC provider.
My observations below:
Convert/Cast on the column with nvarchar datatype did not work -- as in it shows the ???? (This is on SSMS)
When using 3rd Party DB management tools such as Database.net and WinSQL, I was able to see the correct characters.
Playing around with the ODBC driver's Unicode SQL Types function only intermittently helped show the correct characters.
The solution:
Enable Unicode SQL Types function on the ODBC driver
Make changes to the test sql query that is being executed on the Intersystems Cache db. If you keep executing the same query, the output is cached for sometime (not sure how long exactly).
In my case, the sql server cluster was not under my control and took a few days to play around with the different variations.
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".
I was trying to pull data from Oracle to MSSqlserver database using Linked server.
select * from [LINK_NAME]..SCHEMA.TABLE;
But it was failing with the below error:
The OLE DB provider "OraOLEDB.Oracle" for linked server "LINK_NAME"
supplied inconsistent metadata for a column. The column "COLUMN_NAME"
(compile-time ordinal 6) of object ""SCHEMA"."TABLE"" was reported to
have a "LENGTH" of 100 at compile time and 200 at run time.
I also need to pass argument at run time in where condition. I found OPENQUERY as a solution but it does not support arguments at runtime.
Try using the OPENQUERY Syntax to see whether that helps..
SELECT * FROM OPENQUERY(LINK_NAME, 'SELECT * FROM db.Schema.Table')
More about OPENQUERY ...
I found solution:
The error was coming due to database column type mismatch.
ORACLE was using NVARCHAR for datatype but in case of SQLSERVER it was VARCHAR.
As NVARCHAR is double the size of VARCHAR that is why it was showing size mismatch error.
Changing the data type to same worked for me.
I have found a solution posted by this blogger. Try it out!
This tool from Sysinternals/Mark Russinovich is the best, and my only regret that day was not launching it earlier instead of scouring Google and going insane. I’ve limited Procmon to just sqlservr.exe, as it’s the SQL Service itself that loads/handles the providers and not the ssms.exe. Also of note is that the sqlservr.exe is a 64bit process while the management studio is still just 32bit. As the server service is loading the provider, and the service process is 64bit, the provider must also be available in 64 bit format.
The ODAC112021Xcopy_x64.zip was installed to C:\Oracle. What Procmon showed me however is that sqlservr is attempting to find the oci.dll in any folder but his! (It iterates through the %Path% sysvariable). When it finally gives up on find the dll, the SQL Service is in a unstable shape and the only way to stop the service was to kill it via taskmgr/procexp. Clearly I can see that the “xcopy” deployment – while not giving me any error messages – it also did not set the PATH variable! And this is what this post is really about… adding C:\Oracle and C:\Oracle\Bin to the Path variable or maybe it’s about employing investigative tools earlier in the process instead of relying on your search engine skills.
sqlservr.exe can now find the relevant DLL’s. The OCI.DLL in the root and the OraOLEDB11.DLL in the Bin subfolder. At this point I could query the database! If you did my steps as above and you still get the same error, I strongly suggest using Procmon.exe as I have instead of jumping to the next search result.
Full post is here with more details.
I have a big deal: I have to connect (I just want to read data, not to write) to my customer's IBM AS/400 (aka iSeries, now IBM i) server...
I think I have all parameters needed (given me by the AS/400 programmer), but I can't figure out which driver I have to use, and if I have all software needed to to this!
I've installed IBM AS/400 ClientAccess 5.8 driver (with a patch for latest OS), and now I'm trying to configure a new Linked Server in my Sql Server 2008 R2 (x64) server.
First problem: Which driver should I use?
I have so many choices (but maybe none of these works!!):
IBM DB2 UDB for iSeries IBMDASQL OLE DB Provider
IBM DB2 UDB for iSeries IBMDA400 OLE DB Provider
IBM DB2 UDB for iSeries IBMDARLA OLE DB Provider
...or maybe other generic OLEDB/ODBC drivers?!
Second problem: Where should I put my parameters (in which fields I mean!)
In any case, in I choose a provider for my Linked Server, obviously I have to set my parameters...but I only have this:
Username of an ADMIN user
Password of the ADMIN user
AS/400 server IP address
The name of "main" archive, in which my data are stored (something like ACG_DATV2)
Third problem: How should I write my queries? How to reference an AS/400 "archive" and tables?
I don't know how to build my reading query: where are tables and views (?!) stored and how can I reference them?
Thank you in advance!
I think there are many ways to achieve what you want, but I'll try to explain what I would do in your case.
With that version of IBM ClientAccess (and also the patch), I should not have troubles in getting connected with a Sql Server 2008 R2 Linked Server if you use the correct data provider.
First of all, try to configure your linked server in this way:
Linked server name: what you want, it's just a custom name (example: MYAS400)
Provider: IBM DB2 UDB for iSeries IBMDASQL OLE DB Provider
Product name: not important, something like iSeries Access OLEDB Driver
Data source: AS/400 server IP address (example: 192.168.0.1)
Either if you configure the Linked Server using the wizard or by SQL code, the first time it will need to access the data of the AS/400 server, you'll be asked for credentials, with a typical iSeries window (look at my example).
Set your username (User ID) and the relative password, without regarding the case of the strings!!
As a general tip (but this is only related to my experience!), try to avoid special characters and upper/lower cases distinctions...
If you arrive here (no problems in the Linked Server creation), the Linked Server should work (so the first and the second problem are solved): let's build the first query!
Once the Linked Server is created, all you need is just to correctly reference the archive, the library and, of course, the correct table and the Linked Server (by name): with this informations, build a query like this (it's the usual T-SQL syntax):
SELECT
(Field1)
, (Field2)
, *
FROM (Linked Server Name).(Catalog Name).(Library).(TableName)
The only information you're probably missing is the "archive": you can easily find it browsing the Catalogs tree inside your new Linked Server, or just use iSeries Access Navigator tool!
So, in your case, I think the query should be (more or less):
SELECT
FILIO
, DTVLD
, DTVLA
, SEQZA
, CFIMP
, PADRE
, TPVLD
, CMVLD
, *
FROM MYAS400.S242DA0A.ACG_DATV2.ANLE200F
Note that S242DA0A is valid only in my case...
Remember also that:
AS/400 will probably ask you for credentials very often: also if you close and reopen SSMS.
Performance?...better to talk of something else :) ... extract the tables in your Sql Server tables and query them from there! Do it with a simple: SELECT (Fields) INTO myTable FROM (AS/400 table)
I've tried this process many times, I didn't have many troubles (once I get skilled about!)...but only for reading data (as you asked)! Never tried to update data!!!
GOOD LUCK!