问题
I am trying to set-up a connection to a SQL server instance using Linux. My FreeTDS setup seems to work, but my unixODBC set-up does not.
Here is what happens when I access the database with tsql:
tsql -S STCONNSQLDEV\\RscSwitchboard -U sa_RSCSWITCHBOARD -P password
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
Here is what happens when I use isql:
isql RscSwitchboard sa_RSCSWITCHBOARD password -v
[S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source
[37000][unixODBC][FreeTDS][SQL Server]Login failed for user 'sa_RSCSWITCHBOARD'.
[ISQL]ERROR: Could not SQLConnect
My /etc/freetds/freetds.conf:
# $Id: freetds.conf,v 1.12 2007/12/25 06:02:36 jklowden Exp $
#
# This file is installed by FreeTDS if no file by the same
# name is found in the installation directory.
#
# For information about the layout of this file and its settings,
# see the freetds.conf manpage "man freetds.conf".
# Global settings are overridden by those in a database
# server specific section
[global]
# TDS protocol version
; tds version = 4.2
# Whether to write a TDSDUMP file for diagnostic purposes
# (setting this to /tmp is insecure on a multi-user system)
; dump file = /tmp/freetds.log
; debug flags = 0xffff
# Command and connection timeouts
; timeout = 10
; connect timeout = 10
# If you get out-of-memory errors, it may mean that your client
# is trying to allocate a huge buffer for a TEXT field.
# Try setting 'text size' to a more reasonable limit
text size = 64512
# A typical Sybase server
[egServer50]
host = symachine.domain.com
port = 5000
tds version = 5.0
# A typical Microsoft server
[egServer70]
host = ntmachine.domain.com
port = 1433
tds version = 7.0
[STCONNSQLDEV\\RscSwitchboard]
host = 192.168.15.12
port = 1433
tds version = 8.0
client charset = UTF-8
My /etc/odbc.ini:
[RscSwitchboard]
Driver = FreeTDS
Description = ODBC connection via FreeTDS
Trace = Yes
TraceFile = /tmp/rscswitchboard
servername = STCONNSQLDEV\\RscSwitchboard
Database = RscSwitchboard
Port = 1433
My /etc/odbcinst.ini:
[FreeTDS]
Description = tdsodbc
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
[ODBC]
DEBUG=1
Trace = Yes
TraceFile = /tmp/rscswitchboard
My tracefile:
[ODBC][5002][1406656337.564089][__handles.c][450]
Exit:[SQL_SUCCESS]
Environment = 0x14b4750
[ODBC][5002][1406656337.564197][SQLAllocHandle.c][364]
Entry:
Handle Type = 2
Input Handle = 0x14b4750
[ODBC][5002][1406656337.564254][SQLAllocHandle.c][482]
Exit:[SQL_SUCCESS]
Output Handle = 0x14b5080
[ODBC][5002][1406656337.564321][SQLConnect.c][3615]
Entry:
Connection = 0x14b5080
Server Name = [RscSwitchboard][length = 14 (SQL_NTS)]
User Name = [sa_RSCSWITCHBOARD][length = 17 (SQL_NTS)]
Authentication = [********][length = 8 (SQL_NTS)]
UNICODE Using encoding ASCII 'ISO8859-1' and UNICODE 'UCS-2LE'
DIAG [42000] [FreeTDS][SQL Server]Login failed for user 'sa_RSCSWITCHBOARD'.
DIAG [S1000] [FreeTDS][SQL Server]Unable to connect to data source
[ODBC][5002][1406656337.828774][SQLConnect.c][3983]
Exit:[SQL_ERROR]
[ODBC][5002][1406656337.828841][SQLError.c][430]
Entry:
Connection = 0x14b5080
SQLState = 0x7fff8cbb4b10
Native = 0x7fff8cbb4b0c
Message Text = 0x7fff8cbb4b20
Buffer Length = 500
Text Len Ptr = 0x7fff8cbb4b0a
[ODBC][5002][1406656337.828912][SQLError.c][467]
Exit:[SQL_SUCCESS]
SQLState = S1000
Native = 0x7fff8cbb4b0c -> 0
Message Text = [[unixODBC][FreeTDS][SQL Server]Unable to connect to data source]
[ODBC][5002][1406656337.829032][SQLError.c][430]
Entry:
Connection = 0x14b5080
SQLState = 0x7fff8cbb4b10
Native = 0x7fff8cbb4b0c
Message Text = 0x7fff8cbb4b20
Buffer Length = 500
Text Len Ptr = 0x7fff8cbb4b0a
[ODBC][5002][1406656337.829098][SQLError.c][467]
Exit:[SQL_SUCCESS]
SQLState = 37000
Native = 0x7fff8cbb4b0c -> 18456
Message Text = [[unixODBC][FreeTDS][SQL Server]Login failed for user 'sa_RSCSWITCHBOARD'.]
[ODBC][5002][1406656337.829179][SQLError.c][430]
Entry:
Connection = 0x14b5080
SQLState = 0x7fff8cbb4b10
Native = 0x7fff8cbb4b0c
Message Text = 0x7fff8cbb4b20
Buffer Length = 500
Text Len Ptr = 0x7fff8cbb4b0a
[ODBC][5002][1406656337.829234][SQLError.c][467]
Exit:[SQL_NO_DATA]
[ODBC][5002][1406656337.829284][SQLError.c][510]
Entry:
Environment = 0x14b4750
SQLState = 0x7fff8cbb4b10
Native = 0x7fff8cbb4b0c
Message Text = 0x7fff8cbb4b20
Buffer Length = 500
Text Len Ptr = 0x7fff8cbb4b0a
[ODBC][5002][1406656337.829332][SQLError.c][547]
Exit:[SQL_NO_DATA]
[ODBC][5002][1406656337.829423][SQLFreeHandle.c][279]
Entry:
Handle Type = 2
Input Handle = 0x14b5080
[ODBC][5002][1406656337.829477][SQLFreeHandle.c][330]
Exit:[SQL_SUCCESS]
[ODBC][5002][1406656337.829540][SQLFreeHandle.c][212]
Entry:
Handle Type = 1
Input Handle = 0x14b4750
I am using Ubuntu 14.04 x86_64. Does anyone have any suggestions?
回答1:
I would try the following:
== freetds.conf
[global]
charset = UTF-8
client charset = UTF-8
timeout = 10
connect timeout = 10
[server_a]
host = 192.168.15.12
port = 1433
== /etc/odbc.ini
[config_a]
Driver = FreeTDS
Servername = server_a
Database = RscSwitchboard
Port = 1433
$ isql -v config_a sa_RSCSWITCHBOARD password
And if that does not fix it then try the
tds version = 7.3
来源:https://stackoverflow.com/questions/25021978/connecting-to-sql-server-on-linux-tsql-works-isql-cannot-log-in