
freetds를 사용하여 Red Hat 상자에서 Microsoft SQL Server 2005에 연결하는 데 문제가 있습니다. 내 최종 목표는 PHP의 PDO를 사용하여 연결할 수 있는 것이지만 "tsql"을 사용하여 테스트할 때는 연결할 수 없는 것 같습니다.
텔넷으로 접속할 수 있기 때문에 방화벽 문제는 아닌 것 같습니다.
$ telnet <ip> 1433
Trying <ip>...
Connected to <ip>.
Escape character is '^]'.
아래 명령을 실행하면 다음과 같은 결과가 나타납니다.
$ TDSVER=7.1 tsql -H <ip> -p 1433 -U <user> -P <pass>
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
5Error 20003 (severity 6):
Adaptive Server connection timed out
OS error 115, "Operation now in progress"
Error 20002 (severity 9):
Adaptive Server connection failed
There was a problem connecting to the server
내 로컬 데비안 컴퓨터에서 동일한 명령을 실행하면 성공하는 것처럼 보이기 때문에 이것이 올바른 구성이라고 생각합니다.
$ TDSVER=7.1 tsql -H <ip> -p 1433 -U <user> -P <pass>
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1>
"TDSVER=7.0", "TDSVER=7.2", "TDSVER=8.0" 설정으로 연결을 시도했지만 모두 작동하지 않습니다.
오류 로그는 다음과 같습니다.
09:50:45.013838 17363 (log.c:196):Starting log file for FreeTDS 0.91
on 2014-05-09 09:50:45 with debug flags 0xffff.
09:50:45.014138 17363 (iconv.c:330):tds_iconv_open(0x18e63e0, UTF-8)
09:50:45.014334 17363 (iconv.c:187):local name for ISO-8859-1 is ISO-8859-1
09:50:45.014349 17363 (iconv.c:187):local name for UTF-8 is UTF-8
09:50:45.014354 17363 (iconv.c:187):local name for UCS-2LE is UCS-2LE
09:50:45.014358 17363 (iconv.c:187):local name for UCS-2BE is UCS-2BE
09:50:45.014362 17363 (iconv.c:349):setting up conversions for client charset "UTF-8"
09:50:45.014366 17363 (iconv.c:351):preparing iconv for "UTF-8" <-> "UCS-2LE" conversion
09:50:45.014376 17363 (iconv.c:391):preparing iconv for "ISO-8859-1" <-> "UCS-2LE" conversion
09:50:45.014389 17363 (iconv.c:394):tds_iconv_open: done
09:50:45.014400 17363 (net.c:205):Connecting to <ip> port 1433 (TDS version 7.1)
09:50:45.014577 17363 (net.c:270):tds_open_socket: connect(2) returned "Operation now in progress"
09:50:45.019725 17363 (net.c:310):tds_open_socket() succeeded
09:50:45.019751 17363 (util.c:156):Changed query state from DEAD to IDLE
09:50:45.019767 17363 (net.c:741):Sending packet
<censored>
09:50:50.021625 17363 (util.c:331):tdserror(0x18e6140, 0x18e63e0, 20003, 115)
09:50:50.021743 17363 (util.c:361):tdserror: client library returned TDS_INT_CANCEL(2)
09:50:50.021751 17363 (util.c:384):tdserror: returning TDS_INT_CANCEL(2)
09:50:50.021796 17363 (util.c:156):Changed query state from IDLE to DEAD
09:50:50.021808 17363 (login.c:466):login packet rejected
09:50:50.021813 17363 (util.c:331):tdserror(0x18e6140, 0x18e63e0, 20002, 0)
09:50:50.021823 17363 (util.c:361):tdserror: client library returned TDS_INT_CANCEL(2)
09:50:50.021828 17363 (util.c:384):tdserror: returning TDS_INT_CANCEL(2)
09:50:50.021833 17363 (mem.c:615):tds_free_all_results()
여기 내 /etc/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 = 7.1
# 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 = 5
#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
# Define a connection to the MSSQL server.
[mssql]
host = <ip>
port = 1433
tds version = 7.1
편집하다:
무료 TDS 문서에서 7.2를 사용하고 있다고 가정하지만 작동하지 않는 것 같습니다.
http://www.freetds.org/userguide/choosingtdsprotocol.htm
편집 2:
나는 또한 sqsh로 시도했습니다
sqsh -D <dbname> -S <ipaddy> -U <user> -P <password>
sqsh-2.5 Copyright (C) 1995-2001 Scott C. Gray
Portions Copyright (C) 2004-2014 Michael Peppler and Martin Wesdorp
This is free software with ABSOLUTELY NO WARRANTY
For more information type '\warranty'
Open Client Message
Layer 0, Origin 0, Severity 78, Number 35
Adaptive Server connection timed out
답변1
문제는 방화벽 문제였습니다.
내가 아는 한, 내가 이 일을 했을 때
telnet <ip> 1433
Trying <ip>...
Connected to <ip>.
실제로는 서버에 연결되지 않았습니다. 1분만 주면 연결이 끊어질 것입니다. 컴퓨터에 Wireshark를 설치했는데 서버에서 텔넷 요청으로 응답이 전송되지 않는 것을 확인했습니다.
방화벽 문제라는 또 다른 증명은 다른 컴퓨터에서 데이터베이스에 연결할 수 있지만 서버에서는 연결할 수 없다는 것입니다. 그래서 애플리케이션이 구성된 방식이 아니라 네트워크라는 것을 보여주기 위해 SSH 터널을 만들었습니다.
ssh -L 1433:theServerGivingMeIssues:1433 SQLserver
터널 없이도 SQL Server에 연결할 수 있었지만 터널로는 연결할 수 없었습니다.