Visual FoxPro Developer Center > Visual FoxPro Forums > Visual FoxPro General > Need to start learning how to connect to an SQL database from VFP
Ask a questionAsk a question
 

AnswerNeed to start learning how to connect to an SQL database from VFP

  • Wednesday, November 04, 2009 5:21 AMDickDay Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I have never worked with an SQL database and will eventually need to tackle a project that needs to connect to one and extract data into a VFP table.

    The VFP 9 help assumes a higher level of knowledge that I have.  Can anyone suggest how I should get started?  Should I download MySQL or SQL Lite?  Some suggested reading, samples or tutorials?

    Thanks

    Dick Day

Answers

  • Wednesday, November 04, 2009 9:04 AMKalpesh Chhatrala Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    IF You want to Use MySQL then first Install MySQL and MySQL ODBC Driver.

    you can start with from following command..

    lcConnStr = "DRIVER={MySQL ODBC 3.51 Driver}" +;
      ";SERVER=" + lcSvrName +;
      ";DATABASE=" + lcDbName +;
      ";UID=" + lcDbUsrId +;
      ";PWD=" + lcDbPwd +;
      ";OPTION=530"
     
     gnConnHandle = Sqlstringconnect(lcConnStr)
     If gnConnHandle < 0
      lcMsg = 'Cannot establish connection to SQL Server.'
      Messagebox(lcMsg,16,'SQL Server Connect Error')
      glQuit = .T.
     Else
    * Some Code here as per your requirement 
    * you can use SQLEXEC command for get data from table
     Endif



    Please "Mark as Answer" if this post answered your question. :)

    Kalpesh Chhatrala | Software Developer | Rajkot | India

    Kalpesh's Blog
    • Marked As Answer byDickDay Wednesday, November 04, 2009 9:45 AM
    •  

All Replies

  • Wednesday, November 04, 2009 9:04 AMKalpesh Chhatrala Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    IF You want to Use MySQL then first Install MySQL and MySQL ODBC Driver.

    you can start with from following command..

    lcConnStr = "DRIVER={MySQL ODBC 3.51 Driver}" +;
      ";SERVER=" + lcSvrName +;
      ";DATABASE=" + lcDbName +;
      ";UID=" + lcDbUsrId +;
      ";PWD=" + lcDbPwd +;
      ";OPTION=530"
     
     gnConnHandle = Sqlstringconnect(lcConnStr)
     If gnConnHandle < 0
      lcMsg = 'Cannot establish connection to SQL Server.'
      Messagebox(lcMsg,16,'SQL Server Connect Error')
      glQuit = .T.
     Else
    * Some Code here as per your requirement 
    * you can use SQLEXEC command for get data from table
     Endif



    Please "Mark as Answer" if this post answered your question. :)

    Kalpesh Chhatrala | Software Developer | Rajkot | India

    Kalpesh's Blog
    • Marked As Answer byDickDay Wednesday, November 04, 2009 9:45 AM
    •  
  • Wednesday, November 04, 2009 9:45 AMDickDay Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Kalpesh, thank you for such a quick, and easy answer :)  I will begin experimenting with your example, thank you.



    Dick Day
  • Wednesday, November 04, 2009 4:36 PMCraig BerntsonMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    The first thing you need to answer is, which SQL Database will you be using? MySQL, SQL Server, Oracle? Once you answer that, we can help you better.


    Craig Berntson MCSD, Visual FoxPro MVP www.craigberntson.com
  • Wednesday, November 04, 2009 7:41 PMDickDay Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Ultimately, I need to connect to an SQL Server database.  It will be some time before that database is available, so I thought I would start by learning on one of the smaller ones, hoping I could glean enough from my experience to help me with the SQL database.

    Is the syntax different enough that this approach would not work?

    Thanks,
     

    Dick Day