Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

MySQL string connection to FoxPro

MySQL string connection to FoxPro

MySQL string connection to FoxPro


when I tried to connect local / remote MySQL database from VFP using following string connection it returns -1

lnHandle=SQLSTRINGCONNECT("Driver={MySQL OBDC 8.0 Unicode Driver};Server=;Database=w27;User=root;Password=")

but I can connect to both of these database using SQLCONNECT(MySQLOBDEC) DNS Connection created in "ODBC Data Sources (32-bit)"

I am using the same drive IP, Prot No, database, username, and the password in both occasion.

Please help me to solve this issue.

Note I am using Windows 10 pro.


RE: MySQL string connection to FoxPro

You presumably know how to use the Windows ODBC Admin tool. I assume you used that to create "MySQLOBDEC" in your second example.

So, just go to the File DSN tab, and follow the same steps. You will end up with a file containing the connection details. This is an ordinary text file. You can copy the information from that file and paste it directly into the SQLSTRINGCONNECT() parameter (remembering to add the surrounding quotes and to remove the CRLFs).


Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: MySQL string connection to FoxPro

After you get -1 call AERROR(laError) and inspect the error information in the debugger locals window (where you can drill down array elements) or simply output the array info with List Memory Like laError.

One simple reason could be when you have set SQLSetProp(0,"DispLogin",3) you'd not get prompted for missing login information. Instead, it'll let this connection throw an error and you get -1. And that setting is also recommended, as you usually don't want to have an OS dialog pop up in your own UI. Similarly SQLSetProp("DispWarnings,.f.). IIRC these settings are even required on Windows Server 2012 (R2) as these system dialogs cause problems in the VFP process, so you better have all additional information available, ie user and password, usually or promp for them with your own login form and pass them into the other SQLCONNECT parameters (see into the VFP help).

Since any SQL Passthrough function doesn't trigger the CATCH or ON ERROR handling, as the error happens in another process (even on the server, sometimes) you have to get active and look and fetch is by AERROR after SQLConnect or SQLEXEC returns -1. You don't see that information, even if you have error handling established. This also means whenever you go for SQL...() functions and don't get the result you expect, check the information you get from AERROR(). Very general rule, notr only "of thumb".

Bye, Olaf.

Olaf Doschke Software Engineering

RE: MySQL string connection to FoxPro

Thanks Mike
Thanks Olaf

The problem is wording in the string, which should be UI instead of User. I found out this after checking the dsn file.

Olaf, I tried to catch the error with AERROR() but it did not throw anything.


RE: MySQL string connection to FoxPro

I don't know what you tried. not ON ERROR AERROR, but this:


lnHandle=SQLSTRINGCONNECT("Driver={MySQL OBDC 8.0 Unicode Driver};Server=;Database=w27;User=root;Password=")
If lnHandle<0
   set step on

As said, there is no error thrown, you won't get triggered general error handling nor go into a CATCH block, you have to check IF lnHandle<0 and then read the error. You also have to do it then, after it happened, not beforehand.

When SQL(STRING)CONNECT return value sets lnHandle<0 you have guaranteed error information of any kind you retrieve with AERROR().

Bye, Olaf.

Olaf Doschke Software Engineering

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close