SQL Server -> Linked Server to Oracle: "inconsistent metadata" on n+1st query - sql-server

I use LinkedServer to connect SQL-Server with Oracle.
No matter if I use openquery or not, I can only query one single action like "delete" or "insert" on my LinkedServer-Connection. For the n+1st query, I get the following error from SQL-DB:
The OLE DB provider "OraOLEDB.Oracle" for linked server "NAME"
supplied inconsistent metadata. An extra column was supplied during
execution that was not found at compile time.
When I check sessions on OracleDB, I can see that immediately after my query, there is an inactive session from the SQL-Server-Host with a wait-event "SQL*Net message from client". This inactive session disappears after about 60s. Until then, I cannot query any other actions on my LinkedServer-Connection - unless I kill this session manually.
How can I prevent this session from being created and blocking further queries?
Linked-Server-Config:
Provider: Oracle Provider for OLE DB
Provider-Options: "Level zero only" = TRUE, "Allow inprocess" = TRUE
Linked-Server Options: default
Thanks in advance,
Martin
EDIT: Minimal-Repro
At first, I insert data into empty oracle table via
INSERT OPENQUERY
(LINK, 'select COLUMNS from LINKED_TABLE') VALUES (VALUES);
This works.
Next, I insert more data into oracle table, e.g.
INSERT OPENQUERY
(LINK, 'select COLUMNS from LINKED_TABLE') VALUES (DIFFERENT_VALUES);
Now, I get the following error in SSMS:
Msg 7353, Level 16, State 1, Line 5
The OLE DB provider "OraOLEDB.Oracle" for linked server "LINK" supplied inconsistent metadata. An extra column was supplied during execution that was not found at compile time.
If I check oracle sessions, I can see that there is an inactive connection-session for my SQL-Server-Host. Only if I kill this connection-session in Oracle SQL Developer, I can insert (or delete/update) more data. "Select" works without problems.
Hope this helps.

Related

Insert Statement error returned message "the driver cound't identify inserted rows"

I am transferring the data from the local SQL server to a remote (PostgreSQL) table using a Linked server (ODBC). This works perfectly as long as I stick with Select query but fails with Insert, Delete, etc.
Error :
OLE DB provider "MSDASQL" for linked server "DDL_PUYAML1_64" returned
message "the driver cound't identify inserted rows". Msg 7343, Level
16, State 2, Line 75 The OLE DB provider "MSDASQL" for linked server
"DDL_PUYAML1_64" could not INSERT INTO table "[MSDASQL]".
I have tried with Single Value but nothing changes.
As suggested Error messages when you perform an UPDATE, INSERT, or DELETE Transact-SQL statement on a remote table by using the OpenQuery function: "7357" and "7320" here, I have tried with column names instead of "*" and tried putting where 1=0 as well.
Any suggestion/feedback is appreciated.
Thank you!
EDIT: PFB the code
Insert openquery([DDL_PUYAML1_64],'select sn1,encl,encl_model from ws_sls_core.dd_enclosures_forarsdashboard_v1 where 1=0 ')
select sn1,encl,encl_model from #temp1

SQL Server linked server error "The partner transaction manager has disabled its support for remote/network transactions."

I have a linked server (SQL Server 14.0.1000.169). The local server (SQL Server 10.0.1600) receives data in short periods of time, around 1 new row per minute, into Table46. I need to pass some of the information of this new row to the linked server, so I created a trigger in the local server for this:
CREATE TRIGGER New_Event
ON dbo.Table46 FOR INSERT AS
BEGIN
SET NOCOUNT ON;
INSERT INTO [LinkedServer].[Database].[dbo].[TableEvents]
SELECT i.[046_ID] AS [id]
, NP.NoPart + ' ' + CONVERT(VARCHAR(3), T41.[041_No]) AS [name]
, DATEADD(MINUTE, -1 * i.[046_ExeTime], i.[046_DateTime]) AS [eventstart]
, i.[046_DateTime] AS [eventend]
, i.[046_IDRes] AS [resource_id]
, i.[046_ExeTime] AS [execution]
, ISNULL(MIN(T48.[048_MachTime]), 0) AS [same]
, ISNULL(MIN(T48_1.[048_MachTime]), 0) AS [all]
, i.[046_Pallet] AS [pallet]
FROM inserted AS i
INNER JOIN Table41 AS T41
ON i.[046_IDOp] = T41.[041_IDOp]
INNER JOIN NoParts AS NP
ON T41.[041_IDNoPart] = NP.Autonumber
INNER JOIN Table48 AS T48
ON i.[046_IDRes] = T48.[048_IDRes]
AND i.[046_IDOp] = T48.[048_IDOp]
INNER JOIN Table48 AS T48_1
ON i.[046_IDOp] = T48_1.[048_IDOp]
GROUP BY i.[046_ID], NP.NoPart, T41.[041_No], i.[046_MachTime],
i.[046_DateTime], i.[046_IDRes], i.[046_ExeTime], i.[046_Pallet];
END;
The original query after the INSERT INTO works, I just changed Table46 for the inserted virtual table because of the trigger.
Edit 1:
If I add a new row manually to Table46 I get the following error (already started MSDTC service):
OLE DB provider "SQLNCLI10" for linked server "[LinkedServer]" returned message "The partner transaction manager has disabled its support for remote/network transactions.".
Msg 7391, Level 16, State 2, Procedure New_Event, Line 5 [Batch Start Line 15]
The operation could not be performed because OLE DB provider "SQLNCLI10" for linked server "[LinkedServer]" was unable to begin a distributed transaction.
Edit 2:
I have followed these instructions and also allowed MSDTC inbound rules in the Firewall of both servers but now if I try to add the row the query takes a lot of time executing, it hasn't finished yet. The same is happening with a SELECT query to Table46.
What are other ways to insert in the remote server whenever Table46 receives a new row, if triggers don't work?
As mentioned in my comment you need to configure MSDTC to enable distributed transactions between the two linked SQL servers.
If you don't want to do that, then you can use a trigger on the source table to save the required data in a 'queue' table. Then you can have a separate application poll the queue table, fetch data and insert them on the linked server on separate connections (and thus separate transactions). This method may seem suboptimal but does have one advantage: if the linked server is unavailable or slow the source server continues to work at full speed and no data is ever lost.
One way to implement the second approach is to use SQL Server broker. In the trigger send the necessary data to a message queue. On the receiving (linked) server process the messages and insert the data in TableEvents. SQL Server Broker ensures transactional integrity all the way without the use of MSDTC between the two servers while decoupling the two servers. Note that the servers no longer need to be linked anymore (unless you need them linked for some other reason)

Inserting into a table from view create witha link server

I have created a view that includes a view from a linked server and I am inserting into a table. when I query the table it returns no data when the where statement is referencing data from the linkserver table. It does however pull all the data when not using the where statement. why is this for I do not have much experience working with LinkedServers.
Here is code I used to build my view i am using to populate my table.
ALTER VIEW [dbo].[weightsDashboard]
AS
SELECT *
FROM [dbo].[weightsYak]
UNION ALL
SELECT *
FROM OPENQUERY([10.3.50.62\AGJET], 'SELECT * FROM [CheckWeigher].
[dbo].[weightsSs]')
Then I ran this to create the dataset I want to report off of.
select *
into Dataset_SaleSummary
from [dbo].[weightsDashboard]
Thanks in advance.
The root cause Would be driver. Use ODBC instead of OLE DB.If you are trying to connect oracle database from sql server
Delete the linked server from SQL Server
Right click on the "Linked Servers" folder and select "New Linked Server..."
Linked Server: enter anything..this will be the name of your new linked server
Provider: Select "Oracle Provider for OLE DB"
Product Name: enter "Oracle" (without the double quotes)
Data Source: enter the alias from your TNSNAMES.ORA file.
Provider String: leave it blank
Location: leave it blank
Catalog: leave it blank
Now go to the "Security" tab, and click the last radio button that says "Be made using this security context:" and enter the username & password for your connection.
I had exact same problem with an SQL 2014 getting data from SQL 2000 through OPENQUERY. Because ODBC compatibility problem, I had to keep generic OLE DB for ODBC driver. Moreover, the problem was only with SQL non-admin account. So finally, the solution I found was to add SET ROWCOUNT 0:
SELECT * FROM OPENQUERY(DWH_LINK, 'SET ROWCOUNT 0 SELECT * FROM TABLEA ')
It seems the rowcount might been change somewhere through the SQL procedure (or for this user session), so setting it to 0 force it to return "all rows".

Select to Sybase table from SQL Server (by LinkedServer) getting error "db.schema.table was reported to have a "DBCOLUMNFLAGS_ISFIXEDLENGTH" of 16

Select to Sybase table from SQL Server (by LinkedServer) getting error "The OLE DB provider "MSDASQL" for linked server "XXX" supplied inconsistent metadata for a column. The column "XXXX" (compile-time ordinal 1) of object "db.schema.table" was reported to have a "DBCOLUMNFLAGS_ISFIXEDLENGTH" of 16
Query: Select * from [Server].[db].[schema].[table]
Finally after searching some time in the web found the answer, when makes a query on a table having a nullable CHAR column gives the error...
So the solution was create a View in Sybase where I make an ISNULL Validation for the specific column, and from the SQL Server query the View instead the table.
Query: Select * from [Server].[db].[schema].[view]
Source: http://www.dbainfo.net/wp-content/uploads/CR/sdk_17.htm

Importing Excel Data into SQL Server 2008 R2 Express

There seems to have been many discussions on this but I couldn't find something specific to what I am looking for. I am trying to use a query to import data from Excel to an existing table in SQL Server.
My query is:
INSERT INTO DailyRawData
SELECT *
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0 Xml; HDR=NO;
Database=C:\Users\home\Desktop\SQLImportTrim.xls', [data$]);
I get the following error:
Msg 7314, Level 16, State 1, Line 2
The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" does not contain the table "data$". The table either does not exist or the current user does not have permissions on that table.
I don't think this is a permission issue for me as I am set up as SysAdmn. I am wondering if the error is due to the last part of the query [data$] since this is what the error msg refers to. FYI the name of the excel file is SQLImportTrim and the tab that contains all my data is named data. There is no table named data in my Excel file. Is my query correct?
you don't use [data$] you use the name of the sheet, so the standard starting point is usually [Sheet1$] if you haven't renamed it.

Resources