SQL Server, reading and writing data from Oracle 12c. Linked server.
Welcome back!
Today i will show you, briefly, how to read and write data from Oracle directly from your SQL Server installation. Today Key word is linked server!
Are you ready?
Yes i suppose!
Three steps to access data from Oracle (12c)
The first step is installing the Oracle Data Access components that provide the network library required to establish connectivity to the Oracle database.
You must download a zip file named ODAC121021Xcopy_x64 from the oracle official site.
The installation is easy infact you need only to unzip the files and run as administrator the install.bat file.
The installation procedure will create the following dll and exe files:
The second step.
Open the ODBC Data source Aministrator and press add button in the system DNS.
Enter the Oracle datasource name, a description and the user ID.
Third step, the most interesting: create a linked server to Oracle.
Open the SSMS and locate Server Objects item, then locate Linked Server item and finally then Providers item.
If the Oracle Data Access components are correctly installed you should view the item OraOLEDB.Oracle.
In order to create a new Linked Server do right click on the Linked Server voice:
Enter In the form that has opened:
- The Linked server name
- Choose as provider the Oracle Provider for OLE DB
- Enter in the data source field the server name.
Now switch to the Security tab.
As in figure enter the oracle username and password.
The configuration of your linked server is now terminated.
Now you are able to execute select , update and delete directly in the Oracle database.
Note that you could create the same linked server through the T-SQL commands:
For example:
/****** Object: LinkedServer [EASYPROD] Script Date: 22/05/2020 09:04:07 ******/
EXEC master.dbo.sp_addlinkedserver @server = N'EASYPROD', @srvproduct=N'', @provider=N'OraOLEDB.Oracle', @datasrc=N'EASYPROD'
/* For security reasons the linked server remote logins password is changed with ######## */
EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'EASYPROD',@useself=N'False',@locallogin=NULL,@rmtuser=N'XXXX',@rmtpassword='########'
GO
EXEC master.dbo.sp_serveroption @server=N'EASYPROD', @optname=N'collation compatible', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'EASYPROD', @optname=N'data access', @optvalue=N'true'
GO
EXEC master.dbo.sp_serveroption @server=N'EASYPROD', @optname=N'dist', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'EASYPROD', @optname=N'pub', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'EASYPROD', @optname=N'rpc', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'EASYPROD', @optname=N'rpc out', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'EASYPROD', @optname=N'sub', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'EASYPROD', @optname=N'connect timeout', @optvalue=N'0'
GO
EXEC master.dbo.sp_serveroption @server=N'EASYPROD', @optname=N'collation name', @optvalue=null
GO
EXEC master.dbo.sp_serveroption @server=N'EASYPROD', @optname=N'lazy schema validation', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'EASYPROD', @optname=N'query timeout', @optvalue=N'0'
GO
EXEC master.dbo.sp_serveroption @server=N'EASYPROD', @optname=N'use remote collation', @optvalue=N'true'
GO
EXEC master.dbo.sp_serveroption @server=N'EASYPROD', @optname=N'remote proc transaction promotion', @optvalue=N'true'
GO
That'all for today!
Have an amazing weekend my friends.
Luca
SQL: READY TO RUN FASTER?
Comments
Post a Comment