Advertisement
rauljrz

Conexiones de VFP a distintos DMBS

Nov 24th, 2017
1,082
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.01 KB | None | 0 0
  1. #Conexion a MySQL/MariaDB
  2. *------------------------*
  3. * 1) Para crear una conexión a mySQL deberá tener instalado el driver ODBC correspondiente, este se puede descargar del siguiente link: http://www.mysql.com/products/connector/odbc
  4.  
  5. * 2) Definicion de Variables
  6. lcServer ="localhost" &&puede ser una ip 127.0.0.1 // 192.168.1.1
  7. lcUserName="elNombredelUsuario"
  8. lcPassword="laClavedelUsuario"
  9. lcDataBase="laBasedeDatoaUsar"
  10.  
  11. * 3) Cadena de Conexion
  12. lcStringConnect = "DRIVER={MySQL ODBC 3.51 Driver};" + ;
  13. "SERVER=lcServer;" + ;
  14. "UID=lcUserName;" + ;
  15. "PWD=lcPassword;" + ;
  16. "DATABASE=lcDataBase;" + ;
  17. "OPTIONS=131329;"
  18. * 4) La Conexión
  19. SQLSETPROP(0,"DispLogin" , 3 )
  20. lnHandle = SQLSTRINGCONNECT(lcStringConnect)
  21.  
  22. * 5) El Comando a ejecutar
  23. jnResultado = SQLEXEC(lnHandle,"select id, username from user_acl","crsUsuarios")
  24.  
  25. * 6) Desconexion
  26. SQLDISCONNECT(lnHandle)
  27.  
  28. * PD: sensible a mayusculas/minusculas para los nombres de tablas y campos
  29. * aconcejo instalar en MariaDB el correspondiente ODBC descargado de su sitio web.
  30. * OJO... Mucho OJO, si el SO es 32bits, instala ODBC de 32bits, ... No seas marmota!!!
  31. * url's::
  32. * fuente: https://comunidadvfp.blogspot.com/2006/06/vfp-y-mysql.html
  33. * ejemplo 1: https://comunidadvfp.blogspot.com/2014/09/navegacion-en-formularios-abm-en.html
  34. * ejemplo 2: https://comunidadvfp.blogspot.com/2007/06/cliente-servidor-parametrizacion-de.html
  35. * Instalando MySQL (sin XAMPP u otro Paquetes innecesarios): https://dev.mysql.com/doc/refman/5.5/en/windows-install-archive.html
  36. * Instalando MariaDB (como un verdadero development ;) ): https://mariadb.com/kb/en/library/installing-mariadb-windows-zip-packages/
  37. * MariaDB vs MySQL: https://mariadb.com/kb/es/mariadb-versus-mysql-features/
  38.  
  39. #Conexion a SQL Server
  40. *---------------------*
  41. * 1) Para crear una conexión a mySQL deberá tener instalado el driver ODBC correspondiente
  42.  
  43. * 2) IDEM
  44. * 3)
  45. TEXT TO lcStringConnect NOSHOW TEXTMERGE
  46. Driver={SQL Server};Server=<<ALLTRIM(lcServer)>>;Database=<<ALLTRIM(lcDataBase)>>;Uid=<<ALLTRIM(lcUserName)>>;Pwd=<<ALLTRIM(lcPassword)>>;
  47. ENDTEXT
  48.  
  49. * 4) al 6) IDEM
  50.  
  51. #Conexion a Foxpro
  52. *------------------*
  53. * Cadena de conexion:
  54. https://www.connectionstrings.com/visual-foxpro/
  55. .DBC
  56. lcDbc = _samples + [Tastrade\Data\TasTrade.dbc]
  57. lcStringConnect = [Driver={Microsoft Visual FoxPro Driver};SourceType=DBC;SourceDB=] + lcDbc + [;Exclusive=No;NULL=NO;Collate=Machine;BACKGROUNDFETCH=NO;DELETED=NO]
  58. ? SQLStringConnect( lcStringConnect )
  59.  
  60. Tablas Libres
  61. lcDbfDir = _samples + [Solution\Europa\]
  62. lcStringConnect = [Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=] + lcDbfDir + [;Exclusive=No;NULL=NO;Collate=Machine;BACKGROUNDFETCH=NO;DELETED=NO]
  63. lh = SQLStringConnect( lcStringConnect )
  64. ? SQLTables(lh)
  65. Browse
  66. ? SQLExec( lh, "select * from music" )
  67. ? SqlResult.source
  68.  
  69.  
  70. #Conexion a SQLite
  71. *-----------------*
  72. https://www.connectionstrings.com/sqlite/
  73. lcStringConnect ="DRIVER=SQLite3 ODBC Driver;Database=d:\mydb.db;LongNames=0;Timeout=1000;NoTXN=0;SyncPragma=NORMAL;StepAPI=0;"
  74. + "Uid="+lcUserName+";Pwd="+lcPassword
  75.  
  76. #Conexion a Postgre
  77. *-------------------*
  78. https://www.connectionstrings.com/postgre/
  79. lcStringConnect = "Driver={PostgreSQL ANSI};Server="+lcServer+";Database="+lcDataBase+";Uid="+lcUserName+";Pwd="+lcPassword
  80.  
  81. #Conexion a FireBird
  82. *-------------------*
  83. https://www.connectionstrings.com/firebird/
  84. lcCadenaConexion = "DRIVER={Firebird/Interbase(r) driver};" ;
  85. + "USER= " + lcUserName + ";" ;
  86. + "PASSWORD= " + lcPassword + ";" ;
  87. + "DATABASE= " + "C:\Archivos de programa\Firebird\Firebird_2_5\examples\empbuild\Employee.fdb" + ";" ;
  88. + "OPTIONS= 131329;
  89.  
  90. ... y mucho mas en
  91. * https://www.connectionstrings.com
  92. * http://www.carlprothman.net/Default.aspx?tabid=81
  93. * http://www.devlist.com/ConnectionStringsPage.aspx
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement