2

When I'm using mysql client, I can configure my db credentials in ~/.my.ini.

How can I achieve similar thing with sqlcmd on Linux? Where and what filename I should create?

My goal is to avoid keep repeating hostname, user and passwords for every command.

  • If your goal is to avoid repeating, you can factorize the call with a generic function. – Hybris95 Dec 11 '18 at 14:06
1

The odbc.ini for mssql doesn't support the user and password.

Server parameter is used to specify port with syntax [protocol:]Server[,port]

Check /etc/odbcinst.ini for what driver name to use.

$ cat /etc/odbcinst.ini
[ODBC Driver 17 for SQL Server] # must match the 'Driver' in odbc.ini
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.3.so.1.1
UsageCount=1

$ cat /etc/odbc.ini
[ExampleDataSourceName]
Driver=ODBC Driver 17 for SQL Server
Database=example_database_name
Server=tcp:10.1.2.3,50001

$ sqlcmd -D -S ExampleDataSourceName -U user 
|improve this answer|||||
0

MS SQL client is supporting unixODBC. So the credentials can be set in odbc.ini (e.g. ~/.odbc.ini, /etc/odbc.ini). The configuration file can be also specified by ODBCINI environment variable.

Sample content:

[the_db]
    Description = The Database using MyODBC Driver DSN
    SERVER = localhost
    PORT =
    USER = root
    Password = somePassword
    Database = the_db

See: Configuring and Testing iODBC.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.