Configuring mysql linked server with db2 - mysql

I have two database server one is mysql another is db2 both are running on different machine.I want to fetch records from tables from both the database by using a join.i have studied about linked server concept but the problem is i couldnt find any example for creating a linked server with db2(all i can find is SSMS i.e use Sql Server Mannagement Studio for creating linked server) but mine is case is of mysql and db2 and i need to create a linked server to one of them/vice versa.
Please suggest some help how can i achieve this.
Thanks in advance!

In DB2, there is a feature called federation (part of Information Integration), that allows you to present external resources to DB2 (wrapper and nickname); you can query those external resources from DB2, and even you can do joins between different sources (Other DB2 databases, Informix | MSSQL server | Oracle | MySQL databases, flat files, etc.)
In order to query external resources, this feature requieres a special licence. Instead, if you want to query other DB2 or informix databases, this feature does not requiere extra license because it is included as free (these are the IBM databases).
In order hand, there is an option called table functions. These functions return a table when they are called, and then, you can join the returned data with other table. These functions can be developed in SQL PL (IBM procedure language), C or Java.
With this second option, you can create a table function in Java, that queries the MySQL table, and then returns the data to DB2.
I have written an example about how to query a 'topic' in Twitter, and return that data to DB2. You have to do almost the same, but instead of querying Twitter, you configure your other database.
http://angocadb2.blogspot.fr/2012/02/accediendo-tweeter-desde-db2-table.html

#AngocA it doesnt work but thanx for ur suggestion .
After a long search i myself come up with an answer for the above self post and thought of posting it here as it will be helpful for others in case of any combination of scenario where we need to fetch data from two different database server which r remote/local in nature and when linked server concept fails.
We may use a third party jar called as Unity Jdbc which we can use in our java code in simple manner for loading driver then getting connection same like old jdbc.
1)Load driver like thisClass.forName("unity.jdbc.UnityDriver");
2) Get connection like this DriverManager.getConnection(jdbc:unity://test/xspec/mysqldb2.xml);
3) Get Records(DDL/DML)
4)Close Connection
one can visit Unity Jdbc http://www.unityjdbc.com/
Using this jdbc in our code we actualy load an xml based file which has definition of desired datasource of our requirement.
once everything is set one can then easily form a query from two different tables from two different remote databases. syntax : dbname.tablename.fieldname
Addingly we dont need to handle any further xml configuration for closing internal connection created after closing the outer actual connection.
Any issues write revert back.

Related

connecting already existing database in a local environment

I have an access database that connects to a vb6 application and this whole thing is connected between two computers via a shared network one running win 8 and other a win 7, and there is no internet involved in any sorta way nor should it be that is a requirement in fact
sorry I advance I have tried researching on the net but there is really short time and a lot of confusing material online
I am creating a WPF app connected to MySQL DB
now I have copied the access file and imported the contents of the DB in MySQL
things are a real mess in the imported DB so I am fixing it
what I am confused is how I am going to make it work there
do I go and install MySQL and do the whole process manually there, repeating all the steps and changes
is made
make a document that contains the code/script for all the changes I have made and run the data through
it, and is there even a way to implement that as a whole in a singular go
connect both databases together, i don't even know if this is possible
yes, in place of a simple "file share" of the Access file, you now are going to run some kind of SQL server system. In this case MySQL. But it could be PostgreSQL or any kind of "server" database.
That instance of "sql server" thus has to be setup, installed and you ensure that the "box" running that instance of MySQL also allows external connections (often by default the given computer firewall settings prevent this).
At that point, 2 or 10 different computers on that same network can now simply connect to the SQL server. The code of course is going to be VERY simular. You almost for sure used the oleDB provider for use with Access. However, you can use the ODBC provider, or even use the provider from MySQL. Those providers thus means you change the connect object, datareader object etc. However the "base" .net types such as row, or datatable, or dataset can remain as before (so you only change the provider). If you have a lot of code based on oleDB, then you could well consider to contine to use that oleDB provider code in .net, and thus you change the connection strings to now point to MySQL.
If you don't have a lot of code, then for sure do adopt the mySQL provider for .net. But as noted the least amount of changes would be to continue to use a oleDB provider for mysql, and that would suggest the least amount of code to be changed.
As for the msaccess data migration? Well, it not clear what tools and how you doing that now. But, once you transfer the data to the MySQL server (assuming you installed + setup my sql to run on one computer). The it is a simple matter to point your .net connection(s) in your code to Now MySQL as opposed to Acess. As a result, most if not all of your code logic for working with the tables can remain as before - but as noted you have to swap out the provider parts in .net
Now, if your REALLY lucky and the .net code used the ODBC provider? Then all you have to do is change your connection strings. And of course "some" SQL syntax in your code may have to be tweaked, as like Oracle, MS SQL server, postgreSQL, and MySQL?
Well, they all have some features and syntax that is different - this is especially in regards to date/time calculations, datediff() etc. But the general sql you have/had in your .net code should continue to run mostly un-changed against MySQL data tables.
As for how to migrate the data? I think that a really good tool is of course to use MS-Access. What you do is get MySQL up and running. Then use ms-access to open that database. You then add linked tables from MS-access to the MySQL tables.
At that point, you can now run append queries from Access to move/send the data to MySQL. It really depends on how many tables, and how many related tables are in that database. The more complex and the greater number of related tables in Access then the more the challenge to move such data up to MySQL.
Transferring Excel or a small or even big table is a breeze. (again, use MS Access and link to the tables on the sql server). However, where things can become messy is that if you have say 25 tables, and they are all related, many have cascade delete and say enforced parent to child relationships. So the more tables, and especially a larger number of related data tables, then the more work such a data migration task will become.
I think MS Access is a really good tool, since if you setup a connection to MySQL, then you can execute a transferDatabase commend in Access to send up one table to MySQL, and even all the columns and data types for those columns will be automatic created for you. So not only can Access transfer the data, but MORE valuable is it has the abilty to create the target tables on MySQL for you - and that will save you large amounts of time to build + setup the tables on MySQL.

SQL Server views not available via ODBC (reverse Engineer)

SQL Server 2008
Visio Pro 2003
Access 2003
System DSN used
I need to reverse engineer a SQL Server db, however the 'Views' box is "greyed out" when I attempt to do so (stored procedues are also "greyed out" but unecessary for my needs at this stage). I am using a SQL Server account that has sys_admin rights to connect via ODBC (ODBC needs to be used because Visio won't recognise the native connector, a well documented deficiency, and a trusted connection can't be used as I also have local admin rights and our company refuses to recognise local admins on cross machine connections). This is using the ODBC SQL Server type of connection. If I change the ODBC connection to use the native client type it allows me to select the stored procedures, unfortunately the views box is still not able to be selected.
I connected with Access using the plain SQL Server type of ODBC to see what I would be able to link and it allows me to see all tables, views, including system tables and views, which tells me the sys_admin rights are being preserved through the ODBC connection.
Am I missing something here? A number of searches on SO and Google have turned up nothing about why Visio can't see certain objects (disregarding security permissions as I have admin access), and being able to "see" them via Access has made me a bit more frustrated, as I would assume both products utilising an ODBC connection of the same type would encounter the same restrictions and functionality.
How do I get Visio to let me use the "Reverse Engineer" functionality to put the views from the SQL Server into my Visio document? I've done this before with other servers in the past.
I have created several new views in a SQL database and was unable to see them when attempting to link to them via Access. It always comes down to the fact that I have not given the user "Select" permission to either the SQL Database or the view. Be sure to check this. Just my 2 cents worth.
tl;dr
Don't use the OBDC driver, use the Access Visio driver.
Why?
As found here on SO:
An old thread but still a current problem ... I found that although
using the ODBC Generic Driver worked, the reverse engineering tool
then misses out Triggers, Check Clauses, Views and Stored Procedures.
By specifying the Access Visio Driver instead, at least we recover the
Check Clauses and Views.
In general, though, I have to say I think this shows an appalling lack
of regard for their customers on behalf of the relevant teams at
Microsoft. I had a very similar experience last year when upgrading to
Visual Studio 2010 only to discover that my SSIS projects no longer
opened ... as can be seen from this thread, MS could not care less.
There is really no reason to assume that a reverse engineering tool that's capable of documentation or diagraming the relationships between tables has anything to do with the fact that you have some saved queries? A view is only some saved SQL query and has NOTHING at all to do with relationships between tables.
A saved SQL query (aka a view) is NOT a table design structure. The creation of a view or the deletion of a view has NO BEARING WHATSOEVER IN ANY MATERIAL WAY in terms of the database structures and relationships you build in a database.
As a result the reason why with an conservative estimate of 1 trillion web pages in existence a Google or Bing search results in ABSOLUTELY NO RESULTS for your question.
In other words your assumption that a database ER diagram is to include a bunch of saved SQL queries is a complete and utter fallacy on your part.
Now you might be asking if such a documentation tool exists, but you actually asked WHY you cannot find any information on this subject and the simple answer is because nobody else on the planet and in fact as far as we know in the galaxy makes the assumption you're making.
being able to "see" them via Access has made me a bit more frustrated.
And it's not clear why you show even more confusion by asking why you can utilize such views in an application development tool such as MS Access?
The simple answer as to why you can see these views using Access is because Access is not a reverse engineering tool. In fact Access is also not a database documentation tool either.
Access is a software development tool that allows you to build applications and CONNECT TO A GIVEN DATABASE SYSTEM. Thus MS Access can use a database such as the native database engine that ships with the product (JET or now called ACE). Access can also connect to Oracle, or something like SQL server.
In ALL these cases without a doubt Access can connect to a SQL view since the tool is designed to CONSUME data from the particular database engine. However consuming data from a particular database system is a MASSIVE AND SPECTACULARLY DIFFERENT PROCESS then using a reverse engineering tool to ascertain the relationships between tables.
The fact that a database system has some relationships between tables, or you have enforced relationships that you wish to diagram has absolutely nothing to do with the process of having something document a bunch of simple SQL queries saved in some place. So all a view really is some saved SQL. You can save SQL in code, in text files, or in the case of Access in with what we called a select query, or in the case of SQL server you can save SQL as views.
However, looking at a bunch of saved SQL queries is an entirely different matter then documentation the existence of relationships between tables in a database. Creating views, delete views has ZERO bearing on those relationships between tables.
In fact we see that MS Access table diagram tool does not have the ability to include views in the table relationships diagraming tool included with the product. So in fact MOST development tools do NOT include views in the overall table ER diagram.
So at the end of the day the likely reason why something like Visio cannot simply consume and utilize a bunch is saved SQL queries is that by design such a tool is not intended for that purpose at all.

Importing .sql into MS Access using OBDC

I currently have a database in MySQL, which I'd like to import in MS Access.
Is it possible to do this while keeping all relationships intact (i.e. without exporting to .csv, or by using ODBC)?
I'm a noob in this area so any help is greatly appreciated.
Thanks.
You need to solve two different problems:
Creating an empty MS Access database with a structure that matches the MySQL database structure.
Extracting the data from MySQL and loading it into MS Access.
This is not easy because different SQL databases offer different structural features, different datatypes, and so on. The more complex your use of MySQL is the more likely you'll run into some show-stopper during the conversion (for instance, Access doesn't support triggers at all). Conversely if you're using MySQL as a simple data store you may find the conversion fairly easy.
To get an MS Access database with the same structure as your MySQL database, your best bet is to find a database definition / diagramming tool that offers reverse engineering and supports both MySQL and MS Access. Use it to reverse engineer your MySQL database into a database diagram, then change the underlying database to MS Access and use the tool to generate a database.
Check out Dezign For Databases which (on paper, anyway) offers the features you would need to do this.
To pump the data across, there are any number of tools. This kind of operation is generically referred to as ETL (Extract, Translate, Load).
Do you mean SQL Server? A good starting point might be to check out SQL Server Integration Services (SSIS), which can be used for transferring data around like that.
Google will also be helpful, check out the first result:
http://support.microsoft.com/kb/237980
By the way, you said ".sql" in your question: a .SQL file is a script file, which could do anything from create a database, insert data, drop table, delete data, or given the right permissions, call system procedures and reboot a machine, format a drive, send an email.. Just for ref, .SQL files aren't the storage format used by SQL Server.
While you can script your database's schema into script files via something like SQLyog, you will find that the syntax varies enough from database to database (MySQL to Access, in your case) that you can't directly apply the scripts.
With much effort a conversion script could be created by editing the script (perhaps automated with a program, depending on the resulting script size). I think you would be better served using ODBC to copy the tables (and data) and then extracting and re-applying the relationships from the generated script by hand. Time consuming, but also a one time operation I would hope.
When both systems are the same database, there are tools that can do the comparison and script generation (TOAD for MySQL and RedGate Compare for Microsoft SQL), but they don't do cross database work (at least not the ones I am aware of).
If you create a ODBC DSN, you can use TransferDatabase to import from your MySQL database. You can do it manually with the GET EXTERNAL DATA command (or whatever it is in A2007/A2010) and see how well it works. It won't get all data types exactly right, but you could do some massaging and likely get it closer to what will work best.
Is there some reason you can't just link to the MySQL tables and use them directly? That is, why do you need to import into Access at all?
Access: run query. Just make sure to adapt the SQL code since every RDMS has its own sintaxis (despite SQL being an ANSI standard).

connecting Visual Fox Pro to MySql database

I converted visual foxpro DBF to mysql and I need to connect the vfp code directly to the mysql database.Please help.thanks
There are a number of ways to access data from a server database from VFP, but I'm not sure you'd call any of them connecting directly to the server database. Specifically, you can't use commands like USE and REPLACE directly against a server database, nor can you bind form controls directly to the server data.
Whichever approach you use, you pull some data from the server into a cursor in VFP, operate on the cursor, and then, if appropriate, save changes back to the server.
The three main approaches are:
1) Remote views--with this approach, you store SQL queries in a database. To run the query and pull data from the server, you USE the remote view.
2) SQL Pass-Through (SPT)--with this approach, you use the SQLEXEC() command to send SQL commands to the server, and get results.
3) CursorAdapter class--with this approach, you set up a class that describes how you want to get data from the server, and when you call the CursorFill() method, you get a cursor full of data.
You should choose one of these approaches and use it throughout your application. They each have pros and cons.
To get you started, since you'll probably want to use SPT for testing purposes (like in the Command Window) anyway, here's the basics of that approach:
First, you have to connect to the database. You do that with either the SQLConnect() or SQLStringConnect() function. For example:
You'll need to fill in your userid and password where indicated.
nHandle = SQLStringConnect("driver={MySQL ODBC 5.1 Driver};SERVER=localhost;UID=;pwd=")
A positive value for nHandle indicates success. Once you have a handle, you use it to send additional commands. For example:
nSuccess = SQLEXEC(m.nHandle, "SELECT First, Last FROM Customers WHERE State='PA'", "csrPACustomers")
That tells MySQL to execute the query you pass in and put the results in csrPACustomers. nSuccess indicates success or failure.
When you're done, use SQLDisconnect() to close your connection:
SQLDisconnect(m.nHandle)
You can read about all three approaches to remote data in the VFP Help file and on the VFP Wiki (http://fox.wikis.com). Once you decide which approach you want to use, you can ask specific questions.

Can I copy my MySQL database structure to MS Access pre 2007?

I want to create a desktop version of my mysql installation without having to setup a server on my machine.
I want to make use of MS Access' query designer so I can produce complicated queries.
I know I can produce an SQL file but I've no idea how to create an MS Access database from it ?
I'm not going to jump on the "Access sucks" bandwagon, though it can be very frustrating at times.
Worst case, You can start with a blank Access database (mdb file, since you specified pre-2007). Open the query designer & go to SQL view. Paste in one complete SQL statement (CREATE TABLE...), and run it. Fix any incompatibility errors, paste in the next (replacing the first), rinse, repeat. Be sure to do this in such order that any dependency "sources" get created before the dependents.
There may be a batch process available, but I don't know what it is offhand.
Moving from MySQL to something like Access is heading in the wrong direction.
If you need a server-less SQL installation or package as part of your distribution (which is a pretty common requirement these days since admins don't like users to install database servers on their machines), consider SQL Server Compact Edition (CE) or SQL Lite. They're both fully SQL compliant (unlike Access) and will cause you far fewer headaches than Access (which sucks). (Did I mention that Access sucks? Big time?)
SQL CE is a .NET assembly that runs in-process with your app, and is very easy to work with. Also, db objects you create will be upwards-compatibile with the full-blown SQL Server. It also works very, very well with Entity Framework if you're into ORMs.
I've heard praise for SQLite, but haven't worked with it. If you're not on .NET, this should be a good way to go.
Links:
SQL CE
SQLite
I don't know if this is a viable option, but if you can set up a DSN to point to your MySQL server, you can then use FILE | GET EXTERNAL DATA | IMPORT to import your MySQL tables into a blank MDB/ACCDB. It's a one-time operation, but I don't know that there's any other option here. You should get the option to import the table schema only and not schema+data. You may have to tweak data types in the resulting tables, since the MySQL data types won't necessarily map directly to Jet/ACE data types.
Then you can carry the MDB/ACCDB file anywhere you want.