Browsing:

Categorie: Oracle

Creating a linked server ´MySQL to MSSQL´(query the MySQL database without openquery function)

In addition to my previous linked server tutorials, I decided it is time to add MySQL to the linked server series.
In order to have the bug tracking application, Mantis migrated from linux and have it run on a windows environment, I wanted to create a replication between SQL2008 and MySQL, but then I thought, why not try out a virtual linked server again first, to test Mantis isntallation on a Windows based installation, since the online promise of Mantis on a MSSQl environment is not very promising. So today we will create a linked server from MySQl to MSSQL on a windows 2008R 64 bit environment.

Create DNS for MySQL

In order to do so, We first need to install the correct drivers in order to create a ODBC DSN, Just download the drivers from Mysql developers site http://dev.mysql.com/downloads/connector/odbc/ and install them to your database server. DriversIf we see the listed drivers, it means we can create a new DSN, so open up the System DSN tab and ADD a new DSN, you must fill in the correct credentials, for example:ODBC_Connector

Data Source Name: Enter a describing name, so you can see what it does, you might have more linked servers or other connectors running on the same server.
Description: this isnt maditory, but if you want to be more specific, be my guest.
Server: in my case,it’s localhost, as this is a test server and MSSQL and MySQl are on the same server.
Insert username and password, when this is done. The database will display the possible databases you can connect to, in the dropdown.

Click OK and as you can see the System DSN has been added to ODBC.

Create new Linked Server

When this is done, it’s time to open up the MSSQl server and add a new linked server to the Server Objects.4_create_LInkedsname your linked server, I give it the same name as the SystemDSN. And choose the correct provider: Microsoft OLE DB Provider for ODBC Drivers. and datasource equels DSN name.
You need to fill in all the credentials for the provider string, for example:

DRIVER=(MySQL ODBC 5.2 ANSI Driver);SERVER=localhost;PORT=3306;DATABASE=mantisbt; USER=user;PASSWORD=password;OPTION=3;

Note: meaning of OPTION=3 in the MySQL connection string:
Option=1 FLAG_FIELD_LENGHT: Do not Optimize Column Width
Option=2 FLAG_FOUND_ROWS: Return matching rows
Option=3 option 1 and 2 together

Now click OK, this is always the most fun part to me! when it says connection tot the linked server succeeded!

In addition to this, you can enable provider options on the SQLOLEDB, In my case I select the Dynamic Parameter and Allow inprocess.

Now, lets run the test and see if it connects with the databases, as you can see, it connects all the databases available on the MySQL server.

Connection test

But, most important, we can query it directly. Wheeee!

Linked server without OpenQuery function (Tip!)

Maybe you have read other MySQL linked server tutorials before this one and found out that you could only query the mysql database using the openquery() function or maybe that IS  the reason it brought you to this site. Extra, as in extra work, is never fun! With the correct ODBC driver and the right provider options, you can query the MySQl database, just like any other MSSQL database on your MSSQL server. Just follow the tutorial above and don’t forget to  enable the correct provider options. Cheers!


Oracle ODAC installation x64 – Linked server #7302

This will be my last blog on the linked server to an Oracle database.

Linked server is a great solution for easy datatransfer, but the downsite is, that linked servers and windows updates (security) don’t mix very well. Every time you have security updates  your linked server connection with oracle gets corrupted, to be precise, the linked server provider OraOLEDB.Oracle is.

In my last 3 blogs on linked server, we’ve given you multiple solutions.
Troubleshooting a linked server

– building a linked server

– Creating jobs and queries with linked server

This last blog, will show you the easiest way to solve the issue, to the re-install of the oracle client.

29-4-2013 10-58-24

26-4-2013 16-36-54

In our case, we have 2 installations and 2 homes:
– Oracle Db 11g Release 2 Client (11.2.0.1.0) for Microsoft Windows x64 (Oracle11gR2-Client-x64)
– 64-bit ODAC 11.2 Release 5 (11.2.0.3.20) Xcopy for Windows x64 (ODAC1120320_x64)
De Oracle 11.2.0 Client software:
ORACLE_HOME_NAME: OraClient11g_home1
ORACLE_HOME: D:\oracle\11.2.0\client_1

De Oracle 11.2.0.3.20 ODAC software:
ORACLE_HOME_NAME: OraClient11g_home2
ORACLE_HOME: D:\oracle\11.2.0\client_2

We’ve learned along the way, since this isn’t the first time, and troubleshooting got us nowhere, we do it drastically, we’re gonna reinstall the ODAC server in order to have the corrupt oraOLEDB11.dll reinstalled.
We currently have 2 Oracle trees, Home1 for the client in order to have sqlplus to test connections and home2 is the ODAC installation, used for the linked server. So we start with reinstalling ODAC to see if this fixes the oracle connection.

Reinstall ODAC server 1

Now we open the setup exe from the ODAC1120320_64 and choose to deinstall the ODAC products from home2 and press remove…

29-4-2013 10-34-29
Next thing is to restart our server, since the files are still visible in the folder. and the dll have not unloaded.

29-4-2013 10-34-29

Now, reinstall ODAC

29-4-2013 12-21-24

29-4-2013 12-22-21

29-4-2013 12-24-21

29-4-2013 12-24-49

29-4-2013 12-25-22

29-4-2013 12-26-17

To see what we have installed in both dirs:

AvailableProdComponents home1en2

After this, we restart the server and the linked server works.

If you still experience problems, the ODAC install also comes with a script to update ASP.NET providers:

@@InstallOracleASPNETCommon.sql @@InstallOracleMembership.sql @@InstallOraclePersonalization.sql @@InstallOracleProfile.sql @@InstallOracleRoles.sql @@InstallOracleSiteMap.sql @@InstallOracleWebEvents.sql

— Install OracleSessionState Provider — For Oracle 10gR1(10.1.0.2) database and higher, run InstallOracleSessionState.sql — For Oracle 9iR2(9.2.x) database, run InstallOracleSessionState92.sql instead

@@InstallOracleSessionState.sql –@@InstallOracleSessionState92.sql

I hope these linked server blogs have been easy and back to basic tutorials and you found them useful, please let us know if they’ve been helpful to you.


Another oracle error #ORA01219 – restore in online mode

If your database crashed in a active state, you might get an #ORA01219 error.

Tip If you are new to oracle network testing, I recommend you to consult this document: http://docs.oracle.com/cd/E14072_01/network.112/e10836/connect.htm#i429243

This might look like a nightmare, but you can fix the corrupt data pretty easy, you need a oracle console, like SQLPLUS or PLSQL or any tool you like working with and see wich datafiles need to be recovered by typing:

Start by the following query:

Alter database open
 select * from v$datafile;

ora1

ora 3

After trying to open the database, I got the following messageora4


If you see this error, type

--alter database open

and the datafile that needs recovery appearsora5

Repeat the 4 steps below for all the datafiles that need recovery and you have saved the day! Yeeh!

--Select * from v$datafile;
--recover datafile ‘E:\ORADATA\DAT02EBMSDATA.DBF’;
--Select * from v$log;
--Alter database recover datafile 11;

More corrupt files? check out my previous blog: http://www.thebuttonfactory.nl/?p=1256


PAE for optimal use of your 32 bit Oracle server RAM

Physical Address Extension (PAE) is a feature to allow 32-bit x86 processors to access a physical address space (including random access memory and memory mapped devices) larger than 4 gigabytes.

Currently if you run a 32bit windows server oracle can only allocate 4 GB, but you have to enable a PAE function in Windows 2008 in order to fully use the memory provided.

In cmd run As Administrator: ‘Bcdedit /set PAE forceenable’ to see if it works or if you are restricted. run: ‘bcdedit /enum >bcd.txt’ registry entry

sadly PAE seems to not work in standard editions. It’s always better to migrate your oracle server to a 64 bit environment for better performance, especially in newer versions like 11G because 11G tends to use a lot more memory then the 10G versions.

Microsoft article on PAE


Troubleshooting a linked server (error 7302 Could not create an instance of OLE DB provider ‘OraOleDB’)

I spent the last two days looking on internet for a solution on a linked server error know as ‘7302’, there are a lot of hits and the same 3 or 4 solutions keep coming up, I tried them all but no success. To save you from going through endless solutions I am going to sum up all the possible solutions, ending with the most valuable solution, well at least it was the best fix for me.

Here are links to linked server articles I wrote before:

building a linked server
Creating jobs and queries with linked server

Now, the dreading 7302 error Could not create an instance of OLE DB provider ‘OraOleDB’
First a solution that saved our asses last time, but this won’t always do the trick! “After installing a new service pack to the mssql server in 2011, the linked server stopped working, giving an 7302 error ‘Could not create an instance of OLE DB provider ‘MSDAORA’. If your LS stops working after it has been working fine for months and all the tips above are working, i found a quick work around to get your Linked server to work again, just simply check the dynamic parameter box and save and then uncheck it again.”

But this time we didn’t get away with it this easy, almost the same error, different solution needed

once again this error occurs after a series of windows updates we performed, so we started undoing the updates, but ofcourse the error stayed.

On the internet they advise you to change the DCOM security of the MSDAINITIALIZE (Acces Permissions was on Use default, change it to customize, if not already, change the other 2 in customize as well.)

I added the domain user to the permission section. But this solution didn’t work in my case. secondly we opened the Registry and look for: HKEY_LOCAL_MACHINE\SOFTWARE\Classes\AppID\{2206CDB0-19C1-11D1-89E0-00C04FD7A829} and change the owner to administrator, but in my case administrator was already the owner, so no luck here. (source: http://blogs.msdn.com/b/dataaccesstechnologies/archive/2011/09/28/troubleshooting-cannot-create-an-instance-of-ole-db-provider.aspx)

I also checked the Environmental Variables to see if the PATH still contained oracle (e.g. D:/ORACLE/BIN;D:/Oracle/Client;)

Then i tried reconfiguring the Oracle ODAC install in cmd:

D:\oracle>configure
D:\oracle>configure all orahome

but still no luck…

Sometimes restoring your dll files from the day before the error occurs does the trick, but again..nothing.

So, my final solution, re-install the oracle client, this time, with a standard oracle tree that contains some tools to check network and database connection, tnsping and sqlplus.

(re)installing oracle environment:

i used two oracle installations

– Oracle Database 11g Release 2 Client (11.2.0.1.0) for Microsoft Windows x64 (64-bit) this installs the standard oracle home and tools like tnsping and sqlplus

– 64-bit ODAC 11.2 Release 5 (11.2.0.3.20) Xcopy for Windows x64
for a non heavy client for LS to depent on.

first install the oracle 11.2.0.1.0 client and tools.

edit the tns names ora file to your database:

# tnsnames.ora Network Configuration File: D:\oracle\product\10.2.0\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.
Databasename =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = fillinurhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = Databasename)

Secondly we reinstalled the ODAC again, now the OraOleDB drivers are available again. Everything is configured for the LS again. MSSQL needs to reload the OraOLEDB file in, for it will keep the old, corrupt file in use, we need to restart the mssql servers.

So if you walked the same path like me, just reinstall oraclient environment. Good luck!

Special thanks to B. Kooiman for helping with the oracle install!