用于连接到 Ubuntu 上的 SQL 服务器的连接字符串
Connection string for connecting to SQL Server on Ubuntu
考虑这种情况。
SQL 服务器 运行 ubuntu
能够通过 Azure Data Studio 连接
可以通过sqlcmd连接
sqlcmd -S 192.168.99.100,31433 -U sa -P S0mePassw0rd -d friends
-Q "SELECT TOP 5 * FROM dbo.users;"
但我无法使用本地计算机上的 ODBC 通过 C 代码进行连接。
retcode = SQLDriverConnect(hdbc, NULL, connectionstring,
SQL_NTS, outstr, sizeof(outstr), &outstrlen, SQL_DRIVER_NOPROMPT);
retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);
CHECK_ERROR(retcode, "SQLAllocHandle(SQL_HANDLE_STMT)",
SQLDriverConnect
returns -1 和 SQLAllocHandle
失败。
这可能是一个错误的连接字符串,但我尝试了一百个不同的连接字符串都没有成功。
最新的是
Server=friends.laurijssen.local,31433;UID=sa;PWD=S0mePassw0rd;
在端口 31433 和数据库朋友上连接到 192.168.100.99 (laurijssen.local) 的正确字符串应该是什么?
我会试试
Server=laurijssen.local,31433;database=friends;UID=sa;PWD=S0mePassw0rd;
或
Server=192.168.100.99,31433;database=friends;UID=sa;PWD=S0mePassw0rd;
server=
部分应该只是服务器名称(机器名称)或 IP 地址 - 加上端口,如果使用自定义端口;应使用 database=
键
单独指定数据库
参考 https://www.connectionstrings.com/microsoft-sql-server-odbc-driver/
这条线路在本地连接上对我有用:
Server=.,34567;database=DatabaseName;UID=sa;PWD=YourPassword;
考虑这种情况。
SQL 服务器 运行 ubuntu
能够通过 Azure Data Studio 连接
可以通过sqlcmd连接
sqlcmd -S 192.168.99.100,31433 -U sa -P S0mePassw0rd -d friends -Q "SELECT TOP 5 * FROM dbo.users;"
但我无法使用本地计算机上的 ODBC 通过 C 代码进行连接。
retcode = SQLDriverConnect(hdbc, NULL, connectionstring,
SQL_NTS, outstr, sizeof(outstr), &outstrlen, SQL_DRIVER_NOPROMPT);
retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);
CHECK_ERROR(retcode, "SQLAllocHandle(SQL_HANDLE_STMT)",
SQLDriverConnect
returns -1 和 SQLAllocHandle
失败。
这可能是一个错误的连接字符串,但我尝试了一百个不同的连接字符串都没有成功。
最新的是
Server=friends.laurijssen.local,31433;UID=sa;PWD=S0mePassw0rd;
在端口 31433 和数据库朋友上连接到 192.168.100.99 (laurijssen.local) 的正确字符串应该是什么?
我会试试
Server=laurijssen.local,31433;database=friends;UID=sa;PWD=S0mePassw0rd;
或
Server=192.168.100.99,31433;database=friends;UID=sa;PWD=S0mePassw0rd;
server=
部分应该只是服务器名称(机器名称)或 IP 地址 - 加上端口,如果使用自定义端口;应使用 database=
键
参考 https://www.connectionstrings.com/microsoft-sql-server-odbc-driver/
这条线路在本地连接上对我有用:
Server=.,34567;database=DatabaseName;UID=sa;PWD=YourPassword;