SQL Coonection Fails

Discussion in 'Databases' started by peaslee, Jul 14, 2012.

  1. This is what I'm using to see if I can connect to the database:

    Code:
    '
    'to test mySql on server
    '
    'autodefine "off"
    openconsole
    $INCLUDE "sqlext.inc"
    
    
    DEF hEnv,hDBC as UINT
    DEF hStmt as UINT
    DEF rc,cbOut as SWORD
    DEF strConnect[1023],strOut[1023] as ISTRING
    rc = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, hEnv)
    
    IF(rc = SQL_SUCCESS) OR (rc = SQL_SUCCESS_WITH_INFO)
        SQLSetEnvAttr(hEnv,SQL_ATTR_ODBC_VERSION,SQL_OV_ODBC3,SQL_IS_INTEGER)
        rc = SQLAllocHandle(SQL_HANDLE_DBC, hEnv, hDbc)
        IF(rc = SQL_SUCCESS) OR (rc = SQL_SUCCESS_WITH_INFO)
           'ODBC initialized try and connect to a database
            strConnect = "my03.Winhost.com;Initial Catalog=mysql_44925_test;User ID=peaslee;Password=*****;Encrypt=False"
    
            rc = SQLDriverConnect(hDbc,NULL,strConnect,LEN(strConnect),strOut,1023,cbout,SQL_DRIVER_COMPLETE)
            IF rc = SQL_SUCCESS
                'connection established and at this point
                'SQL can be executed, etc. But we will just report success
                'and exit
                PRINT "Database connection established"
                SQLDisconnect(hDbc)
                SQLFreeHandle(SQL_HANDLE_DBC,hDbc)
                SQLFreeHandle(SQL_HANDLE_ENV,hEnv)
            ELSE
               'error so free the connection handle and environment handle
                PRINT "Error connecting"
                SQLFreeHandle(SQL_HANDLE_DBC,hDbc)
                SQLFreeHandle(SQL_HANDLE_ENV,hEnv)
            ENDIF
        ELSE
            'error so free the environment handle
            PRINT "Error allocating connection handle"
            SQLFreeHandle(SQL_HANDLE_ENV,hEnv)
        ENDIF
    ELSE
        PRINT "Error allocating environment handle"
    ENDIF
    
    PRINT "Any key to close"
    DO:UNTIL INKEY$ <> ""
    CloseConsole
    END
    
    
    The connection fails. I assume it's the connection string, but since I'm new at this, I may be going in the wrong direction. Thanks for any help.
     
    Last edited by a moderator: Oct 14, 2015
  2. Elshadriel

    Elshadriel Winhost Staff

    What's the error message you're getting?
     
  3. The function returns -1, but that may be just what this software provides. I'll see if I can get a decent error message in case "-1" doesn't mean anything.
     
  4. The SQLState is "IM008". MSN says the system tried to display a login dialog. Does that make sense?
     
  5. Change last paramter to SQL_DRIVER_NOPROMPT. Now I get IM002.
     
  6. Elshadriel

    Elshadriel Winhost Staff

  7. Elshadriel

    Elshadriel Winhost Staff

    What language is this written in as I'm not that familiar with the syntax?
     
  8. It's a form of Basic from Ionic Wind Software.
     
  9. Some progress. I am able to connect with MySQL Workbench.
     
  10. Elshadriel

    Elshadriel Winhost Staff

    Yeah. My colleague and I found some information on the Internet yesterday prior to your response. The API seems to be written in some derivative of C++. I also didn't notice you were trying to connect to a MySQL database. I'm not sure, but the API might only connect to a Microsoft SQL Server database. In any case, have you tried asking for assistance on their forums? I doubt you'll get many responses here since the language is specialized.
     
  11. I'll try both suggestions. Thanks.
     
  12. Still no luck, but the problem is clearly on my end. There is a feature of Microsoft Access that allows you to create a table that is linked to an SQL server. I got that to work quickly, but I soon realized putting Access on my customers computers would be too expensive. ;)
     
  13. I am so pleased to finally report success. The folks responsible for my flavor of Basic looked at how the compiler dealt with the commands and were able to provide me with the proper function call parameters.

    Thanks for the suggestion and for the help.
     
  14. Wow, cool, I'm glad you worked it out.
     
  15. You're not half as glad as I am :)

    Being able to use my favorite development language with an online database opens up all kinds of possibilitities. And with Winhost.com I get a free website to boot! ;)
     
    Last edited by a moderator: Oct 14, 2015

Share This Page