Cannot connect to sql server from WSL2 Ubuntu

3phpmpom  于 11个月前  发布在  SQL Server
关注(0)|答案(1)|浏览(111)

I am attempting to get Ubuntu 22.04 to talk to mssql server on my Windows machine. The same machine hosting the WSL2 Ubuntu distro. I have installed unixodbc. The odbc.ini file is as follows:

[MYDSN]
Driver="ODBC Driver 18 for SQL Server"
Server=192.168.1.100
Port=1433
Database=mydb

My odbinst.ini file looks like this:

[ODBC Driver 18 for SQL Server]
Description=Microsoft ODBC Driver 18 for SQL Server
Driver=/opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18.3.so.2.1
UsageCount=1

When I execute sudo odbcinst -j I get the following:

DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /root/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8

However, when I execute:

isql -v MYDSN sa "mypassword"

I get the following:

[IM002][unixODBC][Driver Manager]Data source name not found and no default driver specified
[ISQL]ERROR: Could not SQLConnect

I am able to ping the IP address of SQL Server. I have port 1433 open on the Windows firewall and SQL Server is setup to allow remote connections and is using TCP/IP.

eqfvzcg8

eqfvzcg81#

In my troubleshooting I failed to go back and remove the quotes from the following: Driver="ODBC Driver 18 for SQL Server" in the odbc.ini as suggested by AlwaysLearning. Once I removed the quotes, I received a different error [08001][unixODBC][Microsoft][ODBC Driver 18 for SQL Server]SSL Provider: [error:0A000086:SSL routines::certificate verify failed:self-signed certificate] This was fixed by adding Encrypt=no to the odbc.ini file. I found the answer to this issue [here]. 1 I can now connect to sql server using isql.

相关问题