connecting Visual Fox Pro to MySql database - mysql

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.

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.

How to Save an Append or Delete Query in MySQL

So I'm moving from MS Access to MySQL:
In MS Access you can store certain INSERT, DELETE, and UPDATE queries as objects alongside your tables. Thus for anyone who don't understand computers that well, they can click on the objects and automatically run the queries to alter the master table for various business functions.
In MySQL, where and how do you store these queries, I seem to be only able to make tables. When I write a piece of code using the SQL editor, I can only save it to a remote location (such as my local desktop) and not onto the MySQL database, where it's accessible for my coworkers.
If you can't save it onto the server, how would I write a piece of code and execute it within the database that would be easily usable by others.
Thanks
The answer to this question is going to depend on your environment, your users, and your bandwidth to support any given solution. You are gaining a lot by making the switch from Access to MySQL, however you are losing some of the the WYSIWYG features. (e.g., Access forms that can bind directly to your data source.)
There are many approaches:
If your users are more advanced, simply having access to the database using MySQL Workbench may suffice. From there they would have access to run views, stored procedures, or to create their own custom queries.
Another option would be to script your objects using Python and provide a simple gui using TkInter. Python is generally thought of as an easy to use language; with built in suppport for MySQL and TkInter is its "default" interface.
Using the LAMP architecture is another largely popular paradigm using MySQL as the backend database.
There is also nothing stopping you from using Access to link to your MySQL db using MySQL as an external data source.
I hope this provides enough info to help you begin whittling down your options.

Configuring mysql linked server with db2

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.

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.

Update MySQL database from SQL Server in different domain

I am SQL Server developer and the current assignment is little different than what I have done in past. I found Stack Overflow very promising for my problem. I am working on the SQL Server 2005 database for the internal application for my client and the client also got the public facing web application with MySQL database. I do not have any details about this web application, but I got the assignment to update the MySQL database (on public domain) from the SQL Server database (internal domain) on daily basis as auto process. How can I achieve this through the SQL Server?
You might want to try Pentaho Data integrator.
http://wiki.pentaho.com/display/EAI/Latest+Pentaho+Data+Integration+%28aka+Kettle%29+Documentation
The product would allow you to speak to both data technologies. (MSSQL+MySQL) You will find the product similar to DTS. You may be able to construct your solution will little to no code.
SSIS will do this just fine. The hard part is determining how you want to transform the data from one structure to the other (I assume they are not exactly alike in terms of table design.)
But basically you create a dataflow task, connect to the SQL Server for the source data and use a query to define what data you are going to copy, then you do any transformations needed to make the data fit into the MySQL structure and connect to a MySQL destination.
Repeat this process for mulitple data sets you want to send to differnt places.
Once the SSIS pacakge is done, set up configurations so that you can run the package on the production server (you will want to test development to development of course!) then schedule the package to run at an appropriate time.
Depending on how different the two databases are and how much data you need to move, this can be a relatively simple process or very complicated.