我在将 pymssql 连接到本地 MSSQL 实例时遇到问题,并且想使用tsql
FreeTDS 中包含的调试命令。但是,我无法找到 FreeTDS 的安装位置。据我所知,它是在Windows上用pymssql预编译的,我只是不知道它在哪里。
更多信息:
pip
)当我跑步时:
\ngem install tiny_tds\n
Run Code Online (Sandbox Code Playgroud)\n输出告诉我我需要安装 FreeTDS。接下来,它向我展示了一些配置选项,我可能需要一个选项。选项如下:
\n --with-opt-dir\n --without-opt-dir\n --with-opt-include\n --without-opt-include=${opt-dir}/include\n --with-opt-lib\n --without-opt-lib=${opt-dir}/lib\n --with-make-prog\n --without-make-prog\n --srcdir=.\n --curdir\n --ruby=C:/Ruby31-x64/bin/$(RUBY_BASE_NAME)\n --help\n --with-freetds-dir\n --without-freetds-dir\n --with-freetds-include\n --without-freetds-include=${freetds-dir}/include\n --with-freetds-lib\n --without-freetds-lib=${freetds-dir}/lib\n --with-sybdb-dir\n --without-sybdb-dir\n --with-sybdb-include\n --without-sybdb-include=${sybdb-dir}/include\n --with-sybdb-lib\n --without-sybdb-lib=${sybdb-dir}/lib\n --with-sybdblib\n --without-sybdblib\n --with-sybdblib\n --without-sybdblib\n
Run Code Online (Sandbox Code Playgroud)\n问题是所有选项都不起作用。Here\xc2\xb4s 是所发生情况的示例:
\nC:\\RailsApps>gem install tiny_tds -- --with-freetds-dir\nTemporarily enhancing PATH for MSYS/MINGW...\nUsing msys2 packages: mingw-w64-ucrt-x86_64-freetds\nBuilding native extensions with: '--with-freetds-dir'\nThis could take a while...\nERROR: Error installing tiny_tds:\n ERROR: Failed to build gem native extension.\n\n current directory: C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/tiny_tds-2.1.5/ext/tiny_tds\n C:/Ruby31-x64/bin/ruby.exe -I C:/Ruby31-x64/lib/ruby/3.1.0 -r ./siteconf20220308-11104- \n …
Run Code Online (Sandbox Code Playgroud) 我有2个服务器:一个是OpenSUSE系统,另一个是SLES 11 SP2的SUSE Linux Enterprise Server中.
为了连接到MSSQL,我必须为php安装mssql.so.
OpenSUSE允许从rpm安装mssql.SLES - 没有mssql rpm,这就是为什么需要编译它.
OpenSUSE:mssql rpm installed =>
$server="172.x.x.x:49888";
$username="username";
$password="password";
$link = mssql_connect($server, $username, $password);
Run Code Online (Sandbox Code Playgroud)
这里成功连接到MSSQL!
SLES:用mssql.so编译=>
$server="172.x.x.x:49888";
$username="username";
$password="password";
$link = mssql_connect($server, $username, $password);
Run Code Online (Sandbox Code Playgroud)
错误:警告:mssql_connect():无法连接到服务器:172.xxx:49888
如果我编辑freetds.conf
#A typical Microsoft server
[Dovico]
host = 172.x.x.x
port = 49888
tds version = 7.0
Run Code Online (Sandbox Code Playgroud)
并改变这样的PHP:
$server="Dovico";
$username="username";
$password="password";
$link = mssql_connect($server, $username, $password);
Run Code Online (Sandbox Code Playgroud)
=>成功连接到MSSQL!
所以我的问题是我怎么能对SLES MSSQL的连接(与mssql.so编译)在使用本
mssql_connect("172.x.x.x:49888", "username", "password");
Run Code Online (Sandbox Code Playgroud)
而不是使用freetds.conf?
每当我尝试构建DBD::Sybase
连接到MSSQL时,我都会收到错误,
$ sudo cpanp install DBD::Sybase
Installing DBD::Sybase (1.15)
Running [/usr/bin/perl /usr/bin/cpanp-run-perl /home/ecarroll/.cpanplus/5.14.2/build/DBD-Sybase-1.15/Makefile.PL INSTALLDIRS=site]...
Can't find any Sybase libraries in /etc/lib or /etc/lib64 at /home/ecarroll/.cpanplus/5.14.2/build/DBD-Sybase-1.15/Makefile.PL line 155, <IN> line 44.
BEGIN failed--compilation aborted at /usr/bin/cpanp-run-perl line 11, <IN> line 44.
[ERROR] Could not run '/usr/bin/perl Makefile.PL': Can't find any Sybase libraries in /etc/lib or /etc/lib64 at /home/ecarroll/.cpanplus/5.14.2/build/DBD-Sybase-1.15/Makefile.PL line 155, <IN> line 44.
BEGIN failed--compilation aborted at /usr/bin/cpanp-run-perl line 11, <IN> line 44.
-- cannot continue
[ERROR] Unable to …
Run Code Online (Sandbox Code Playgroud) 我有一个 pydodbc 游标连接到 Azure SQL 数据库,其中安装了最新版本的 FreeTDS,在 Mac OS Sierra 10.12.6 上运行:
cursor.execute("CREATE TABLE test(a INT, b INT)")
cursor.commit()
Run Code Online (Sandbox Code Playgroud)
这行得通,那我试试
cursor.fast_executemany=True
cursor.execute("INSERT INTO test(a, b) VALUES(?,?)", [(1,2),(3,4),(5,6)])
Run Code Online (Sandbox Code Playgroud)
这导致分段错误,我看到的唯一错误消息是 segmentation fault: 11
如果我没有设置cursor.fast_executemany=True
,那么代码工作得很好。
我正在使用带有PHP PDO的MS SQL Server 2008:我有一个PHP PDO类,它采用Windows字符集并手动将数据转换为UTF-8.就像是:
$sql = "SELECT * FROM something_somewhere);
$query = $this->db->query($sql);
$result = $query->fetchAll(PDO::FETCH_OBJ);
foreach ($result as $row) {
foreach (get_object_vars($row) as $key => $value) {
$row->$key = (mb_detect_encoding($value, mb_detect_order(), true) === 'UTF-8')
? $value : iconv('iso-8859-1', 'utf-8', $value);
}
$results[] = $row;
Run Code Online (Sandbox Code Playgroud)
}
iconv()效果很好,但是一直写这个很乏味.反正有没有配置FreeTDS转换为UTF-8?
我正在阅读关于Moodle的FreeTDS配置:
https://docs.moodle.org/22/en/FreeTDS
我当前的/etc/freetds.conf文件(不可编辑,所以我必须让管理员更改它):
# $Id: freetds.conf,v 1.12 2007/12/25 06:02:36 *** Exp $
#
# This file is installed by FreeTDS if no file by the same
# name is found in …
Run Code Online (Sandbox Code Playgroud) 我们正在运行一个完全无条件的查询,并收到以下错误:
PDOException : SQLSTATE[24000]: Invalid cursor state: 0 [FreeTDS][SQL Server]Invalid cursor state (SQLExecute[0] at /builddir/build/BUILD/php-5.5.13/ext/pdo_odbc/odbc_stmt.c:254)
Run Code Online (Sandbox Code Playgroud)
从PHP中,我们正在使用该pdo_odbc
库通过FreeTDS连接到SQLServer 2008
我正在尝试通过我的 MacBook 连接到我公司的 SQL Server 数据库,并按照此处概述的步骤操作:https : //github.com/mkleehammer/pyodbc/wiki/Connecting-to-SQL-Server-from-Mac-OSX但当我进入以下步骤时,不断收到以下错误:
通过运行检查一切是否正常isql TEST myuser mypassword
。您应该看到以下内容:
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
Run Code Online (Sandbox Code Playgroud)
我已经验证了以下工作:
使用 tsql 实用程序测试连接,例如tsql -S TEST -U myuser -P mypassword
. 如果这有效,您应该看到以下内容:
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1>
Run Code Online (Sandbox Code Playgroud)
odbcinst.ini 和 odbc.ini 配置文件都在同一目录中。
MacBook-Pro: myname$ odbcinst -j
unixODBC 2.3.7
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources …
Run Code Online (Sandbox Code Playgroud) 我正在使用tsql(与FreeTDS一起安装),我想知道是否有办法从命令行在tsql中运行SQL脚本并将结果存入文本文件.
例如,在psql中,我可以这样做:
psql -U username -C "COPY 'SELECT * FROM some_table' to 'out.csv' with csv header"
Run Code Online (Sandbox Code Playgroud)
要么:
psql -U username -C "\i script.sql"
Run Code Online (Sandbox Code Playgroud)
并在script.sql中执行:
\o out.csv
SELECT * FROM some_table;
Run Code Online (Sandbox Code Playgroud)
有没有办法在tsql中这样做?我已经阅读了linux手册页并在各处搜索,但我找不到方法.
这让我很难过.我从i-net Clear Reports中复制并粘贴了一条SQL语句,并将其粘贴到Windows编辑器中,该编辑器正在编辑Ubuntu .sql文件,该文件只是一个文本文件.我已经连接到另一个MS SQL 2005服务器,没有问题通过isql和Perl.所以我遇到了一个带有大约10个连接的大型SQL语句的问题,并将语句简化为以下多行:
SELECT PKG.SO_ID
FROM
PACKAGES AS PKG
WHERE
PKG.tracking_no = '640038823199'
;
Run Code Online (Sandbox Code Playgroud)
此文件由多行带有unix行结尾组成.我的isql命令是:cat test1.sql | isql dsnname 'domain\username' password -v -b
.
我使用-b作为批处理模式,因为我通过文件向isql发送输入.错误在第一行立即开始,但我仔细检查了语法,对于SQL Server 2005,'AS'在'PACKAGES AS PKG'中是可选的.
[37000][unixODBC][FreeTDS][SQL Server]Statement(s) could not be prepared.
[37000][unixODBC][FreeTDS][SQL Server]The multi-part identifier "PKG.SO_ID" could not be bound.
[ISQL]ERROR: Could not SQLExecute
[37000][unixODBC][FreeTDS][SQL Server]Incorrect syntax near the keyword 'FROM'.
[37000][unixODBC][FreeTDS][SQL Server]Statement(s) could not be …
Run Code Online (Sandbox Code Playgroud)