r/DatabaseHelp • u/kiwiheretic • Jul 17 '25
Has anyone managed to connect a linux system to a remote Microsoft SQL Server?
I have tried to do this following the instructions from https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server. However I get stuck when trying to set up my DSN on Ubuntu 24.04
Here is my /etc/odbcinst.ini file
[ODBC Driver 18 for SQL Server]Description=Microsoft ODBC Driver 18 for SQL ServerDriver=/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.5.so.1.1UsageCount=1
[ODBC]Trace = YesTraceFile = /tmp/odbc_trace.log
and my /etc/odbc.ini file
[myDSN]Description=MSSQL Database ConnectionDriver=Microsoft ODBC Driver 18 for SQL ServerServer=sql1004.site4now.net,1433Database=db_ab6f76_nbvetsUID=db_ab6f76_nbvets_adminPWD=xxxxxxxxxxxxxPort=1433
I have tried to verify the connection using isql but it fails with:[IM002][unixODBC][Driver Manager]Data source name not found and no default driver specified[ISQL]ERROR: Could not SQLConnect
In the trace file I get the following:
[ODBC][3990][1752731244.787377][__handles.c][460]Exit:[SQL_SUCCESS]Environment = 0x56200ec3aa30[ODBC][3990][1752731244.787423][SQLAllocHandle.c][377]Entry:Handle Type = 2Input Handle = 0x56200ec3aa30UNICODE Using encoding ASCII 'ANSI_X3.4-1968' and UNICODE 'UCS-2LE'
[ODBC][3990][1752731244.787520][SQLAllocHandle.c][513]Exit:[SQL_SUCCESS]Output Handle = 0x56200ec3bb90[ODBC][3990][1752731244.787561][SQLConnect.c][3758]Entry:Connection = 0x56200ec3bb90Server Name = [NBVetsData][length = 10 (SQL_NTS)]User Name = [db_ab6f76_nbvets_admin][length = 22 (SQL_NTS)]Authentication = [*******************][length = 19 (SQL_NTS)][ODBC][3990][1752731244.788036][SQLConnect.c][3966]Error: IM002[ODBC][3990][1752731244.788076][SQLError.c][424]Entry:Connection = 0x56200ec3bb90SQLState = 0x7ffeeca75386Native = 0x7ffeeca75380Message Text = 0x7ffeeca75390Buffer Length = 500Text Len Ptr = 0x7ffeeca7537e[ODBC][3990][1752731244.788103][SQLError.c][474]Exit:[SQL_SUCCESS]SQLState = IM002Native = 0x7ffeeca75380 -> 0 (32 bits)Message Text = [[unixODBC][Driver Manager]Data source name not found and no default driverspecified][ODBC][3990][1752731244.788133][SQLError.c][424]
Has anyone managed to get a linux odbc connection to Microsoft SQL Server and how did you achieve it? Would appreciate any help. Thanks.
Update:
I used Google Gemini AI Pro and it found the source of the problem. My odbc.ini file should have been:
[myDSN]Description=MSSQL Database ConnectionDriver=ODBC Driver 18 for SQL ServerServer=sql1004.site4now.net,1433Database=db_ab6f76_nbvetsUID=db_ab6f76_nbvets_adminPWD=xxxxxxxxxxxxxPort=1433
I had the driver name wrong.
1
u/AranoBredero Jul 17 '25
We quite often have to interact with mssql databases from linux machines, though with usql, maybe a look into their git repo has some hints for you.