execute Oracle stored procedure from SQL Server 2012 - sql-server

I have changed variable names to protect customer.
I am trying to execute a stored procedure from a remote Oracle 12c database, from my SQL Server 2012 database. If it helps, the Oracle database pl/SQL procedure is has input data types of: INPUT1=CHAR(200), INPUT2=(NUMBER), OUTPUT=SYS_REFCURSOR
I am constantly getting the following error:
"OLE DB provider "OraOLEDB.Oracle" for linked server "testsrv1" returned message "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.""
My query is found below:
DECLARE #outputParameter int
DECLARE #inputParameter varchar(400)
DECLARE #inputParameter1 varchar(400)
set #inputParameter1 = 'SampleStringValue'
set #inputparameter = SampleNumberValue
EXEC ('BEGIN storedProcedure(?,?); END;', #inputParameter, #inputParameter1, #outputParameter OUTPUT) at testsrv1

After many hours of research, I found that you cannot return a SYS_REF_CURSOR data type over a database link. Even from an Oracle database to another Oracle database.
https://asktom.oracle.com/pls/apex/asktom.search?tag=returning-result-set-from-stored-procedure-over-a-database-link
If Oracle database A is the DB producing the SYS_REF_CURSOR, and database B is the consumer - the only way that I have found online is to retrieve the data inside database A and store into a table, then pass the table via database link.
Is this really the only way to do this? I am somewhat new to oracle, but this seems like something that should be able to be done by now. The link from above is from 10+ years ago.

You can use SSIS and the SSIS Data Streaming Destination to connect to Oracle in SSIS and consume the output of the SSIS package in a SQL Query.
From SSIS you can use OleDB, ODBC, ADO.NET connectors for Oracle, or you can use a .NET script to connect to Oracle.

Related

Linked servers (MySQL in SQL Server) brings tables without columns

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.

No column information was returned by the SQL command. SSDT

I'm attempting to create an update query in SSDT. I'm getting
Unable to parse query text.
The query is:
UPDATE CustOrderWithDisp
SET YARDS = CustOrderWithDisp.QUANTITY * Lkp_TestCodes.[Test_GALS] * 0.00495113
FROM CustOrderWithDisp
INNER JOIN Lkp_TestCodes
ON CustOrderWithDisp.TEST_CODE = Lkp_TestCodes.[SVC CODE]
But if I actually run the query, it works.
I want to use this query in an SSIS package. When I put this query in an OLEDB Source, i get...
The component reported the following warnings:
Error at qry03_CalculateYards [OLE DB Source [33]]: No column information was returned by the SQL command.
I'm a novice at this, so be gentle. Your help is greatly appreciated!
Error at qry03_CalculateYards [OLE DB Source [33]]: No column information was returned by the SQL command.
You are receiving this message because OLEDB Source is a DataFlow Task component, it is used to read data from an Table or SQL Command through an OLEDB Connection.
The OLE DB source extracts data from a variety of OLE DB-compliant relational databases by using a database table, a view, or an SQL command. For example, the OLE DB source can extract data from tables in Microsoft Office Access or SQL Server databases.
You don't have to put this query in an OLEDB Source, you have to use an Execute SQL Task and write this query in the SQL Command property.
For UPDATE queries you have to use Execute SQL Task (in the Control Flow level, no in the DataFlow)
The Execute SQL task runs SQL statements or stored procedures from a package. The task can contain either a single SQL statement or multiple SQL statements that run sequentially.
References
Execute SQL Task
OLEDB Source

SQL Server / IBM DB2 interoperability

I'm working on a project that involves capturing data from an external service and relaying it into an IBM DB2 database. Data captured by the Web API is stored in SQL Server via Entity Framework 6 code. The table in SQL Server was structured after an existing table in DB2, using a generated script from System i Navigator to create an ISO Standard create script.
Remote Service --> Web API --> SQL -/-> DB2
The DB2 Server is set up as a linked server. I am able to select from its libraries and perform inserts manually from SQL Server Management Studio.
My goal is to run a query of the form:
INSERT INTO LinkedServer.SCHEMA.Table (Column1, Column2, Column3,...)
SELECT
(Column1, Column2, Column3,...)
FROM
database.dbo.Table
However, when I attempt to run the above query, I am met with messages like these:
OLE DB provider "IBMDASQL" for linked server "SERVER" returned message "CWBZZ5014 Value of parameter PARAMETER could not be converted to the host data type.".
OLE DB provider "IBMDASQL" for linked server "SERVER" returned message "CWBZZ5013 Cannot convert from CCSID 13488 to CCSID 937.".
OLE DB provider "IBMDASQL" for linked server "SERVER" returned message "CWBZZ5013 Cannot convert from CCSID 1202 to CCSID 937.".
I think there is something weird about how the insert statement is handling character encoding for all of the char(N) columns in the table, but I have no idea what to do about it. Have I missed something?

How to add Sybase SQL Anywhere DB as linked server to MS SQL Server properly

I used the Microsoft OLE DB Provider for SQL Anywhere to create a linked server, it shows remote databases and tables, I can read data, but writing data seems to work only using OPENQUERY() and when doing the connection_authentication using EXEC ... AT ... directly in the script.
How can I have the SQL Server do the authentication automatically when opening a connection?
How can I make normal write operations work without OPENQUERY()?
Sorry for not adding detailed error messages, I will add them later maybe, when I have access to the server again... But they were not meaningful anyway, i.e. when the weird authentication was missing, it just said "could not insert" or "failed" instead of indicating any authentication issue.
How to get the real error messages that come from Sybase?
Details:
SAP Sybase SQL Anywhere 16 (OEM Authenticated Edition) <-> MS SQL Server 2014
EXEC 'SET TEMPORARY OPTION CONNECTION_AUTHENTICATION=''Company=...''' AT linkedserver
INSERT INTO OPENQUERY(linkedserver, 'SELECT column FROM table WHERE 0=1') VALUES ('')
...that's not nice.
Even more details:
This is how I created the linked server
This is the authentication I'm talking about

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.

Resources