linux connectivity sqlcmd works but c code does not


  • This question has been asked before by others, "answered" and moved, but no real answer. I have Linux driver 11 set up and am trying to connect to a Windows machine with sql server from on fedora 19x64. If I use sqlcmd on Linux terminal with -S Server..., I connect, but no matter what I seem to do with an adapted C program that was provided by a MS person on a blog It fails at the

    // Connect to data source     
                retcode = SQLConnect(hdbc, (SQLCHAR*) "SQLCMD", SQL_NTS, (SQLCHAR*) "Test1", 5, (SQLCHAR*) "Password1", 9); 

    with changes to the arguments for me like

    // Connect to data source     
                retcode = SQLConnect(hdbc, (SQLCHAR*) "trogw", 5, (SQLCHAR*) "XX", 2, (SQLCHAR*) "XXXXXXXXXX", 10);      

    That -H fails to connect on sqlcmd but -S works makes me think something is amiss with the connection string in the c code, or the character width/encoding is not right....

    It would be nice to see someone's working connection code.   

    Friday, November 01, 2013 5:51 PM

All replies

  • Hi mwindham,

    First, I want to inform that “-H” option is used to specify the current host name where the “SQLCMD” command executes rather the server name where the SQL Server instance runs, we can ignore this option rather the the “-S” option. This can explain the following result:

    That -H fails to connect on sqlcmd but -S works

    Since we can connect to the SQL Server instance via “SQLCMD”, it indicates the ODBC driver works and this issue is more likely caused by C++ codes. I want to inform that this forum is to discuss SQL Server questions. Regarding the C++ codes issue, I suggest posting the question to C++ forum. Additionally, I want to confirm what’s the error message you received when executing the following command:

    // Connect to data source      
    retcode = SQLConnect(hdbc, (SQLCHAR*) "trogw", 5, (SQLCHAR*) "XX", 2, (SQLCHAR*) "XXXXXXXXXX", 10); 

    For more detail information, you can refer to the following link:

    Connecting with sqlcmd

    Best Regards,
    Allen Li

    If you have any feedback on our support, please click

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

    Monday, November 04, 2013 2:10 AM
  • That such, though well intended, is considered an answer is sad.
    Thursday, November 14, 2013 2:42 PM
  • Hello mwindham ,

    I disagree with you : if it is not working for you , you should have replied to the Allen's post before posting a reply 9 days later, a timespan usually considered as an agreement.

    Have a nice day

    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.

    Thursday, November 14, 2013 9:08 PM
  • I was hoping someone knew an answer in that time period, as the post eventually marked the answer did not seem to get the problem as described.

    I will have a nice day, thank you.

    Friday, November 15, 2013 12:36 AM