Connection string for my SQL Server connection from C on Linux

Arek 96 Reputation points
2021-07-26T10:25:38.197+00:00

Hello

I am trying to connect to SQL Server using C program on Linux. Server's IP is 192.168.0.25 and Port is 52000.

I can connect to it using below:

isql test ud pw -v

My connection string is this:

DRIVER = {ODBC Driver 17 for SQL Server}; Server = 192.168.0.25,52000;Database = db; UID = ud, PWD = pw;

When I want to perform a test connection, I get this error:

[unixODBC][Microsoft][ODBC Driver 17 for SQL Server]Login failed for user ''

Something must be wrong with the connection string because it shows empty user '', not 'ud' as in the string above. Why it does not pass my credentials?
I'll be grateful for any help

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,779 questions
{count} votes

Accepted answer
  1. Arek 96 Reputation points
    2021-07-28T06:30:02.147+00:00

    Sorry for the comma instead of semicolon. I was retyping it from another machine so it was just a typo here.
    What in fact helped was to add those three options:

    Authentication=SqlPassword; Trusted_Connection=no;Encrypt=no;
    

2 additional answers

Sort by: Most helpful
  1. Olaf Helper 44,501 Reputation points
    2021-07-27T07:00:48.107+00:00

    Your connection string look good so far: https://www.connectionstrings.com/microsoft-odbc-driver-17-for-sql-server/
    Do you see any details about the failed login attempt in SQL Server ErrorLog file?

    View the SQL Server error log in SQL Server Management Studio (SSMS)


  2. CathyJi-MSFT 22,201 Reputation points Microsoft Vendor
    2021-07-27T07:12:09.717+00:00

    Hi @Arek ,

    Please try below connection string;

    DRIVER = {ODBC Driver 17 for SQL Server}; Server = 192.168.0.25,52000;Database = db; UID = ud; PWD = pw;  
    

    Quote from the blog Microsoft ODBC Driver 17 for SQL Server connection strings.

    118168-screenshot-2021-07-27-151406.jpg


    If the response is helpful, please click "Accept Answer" and upvote it, as this could help other community members looking for similar queries.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.