Latest Articles related to all categories. Microsoft, Twitter, Xbox, Autos and much more

Full width home advertisement

Post Page Advertisement [Top]

If we build an application using Visual FoxPro, using the MySQL database server, then "connection string" is better than ODBC. Why do I say so? If we use "connection string", we no longer need to set the datasource (ODBC) on client computers that will access the MySQL database server. We just install MySQL Connector ODBC that we can download onhttp://dev.mysql.com/downloads/connector/odbc/

Other advantages using "connection string" is that we simply declare a variable 'PUBLIC' in the initial application or in code ("Command") key only. So if one day our server problems and had to change in another IP we simply replace only one line syntax in that "Command".
Below suppose we have the MySQL database server:

IP Server : 192.168.1.50
MySQL Connector : MySQL ODBC 5.1 Driver
Port : 3306
Database Name : dbTry
User : usrTry
Password : pswdTry
We can declare once a "PUBLIC" variable suppose that the variable name is "MyCon"

PUBLIC MyCon
MyCon="DRIVER={MySQL ODBC 5.1 Driver};SERVER=192.168.1.50;PORT=3306;DATABASE=dbTry; USER=usrTry;PASSWORD=pswdTry;OPTION=3;"

To use "MyCon" connection variable in any forms, we use a variable suppose "xCon"

xCon = SQLSTRINGCONNECT(MyCon)
IF xCon <= 0
   MESSAGEBOX("Connection Error",0+16, "Error")
ENDIF
msql= "SELECT * FROM Student ;"
IF SQLEXEC(xCon,msql,"cStudent") <= 0
    MESSAGEBOX("Can't Call Student Database",0+16,"Error")
    SQLDISCONNECT(xCon)
    RETURN
ENDIF
SQLDISCONNECT(xCon)

The above command calls the Student Table and accommodated at Cursor "cStudent"
Thus, hopefully useful

1 comment:

Bottom Ad [Post Page]