如何在Mac OSX上使用Vim dbext连接到MS SQLServer?

时间:2011-04-14 07:01:04

标签: sql-server vim macvim

我使用MacVim和dbext插件连接到Oracle,效果很好。现在我需要连接到MS SQLServer, 但它显示错误:

Connection: T(SQLSRV) H(localhost) U(user) at 14:38 /bin/bash: osql: command not found

任何人都知道怎么做?

3 个答案:

答案 0 :(得分:3)

确保您拥有一个FreeTDS CLI程序。我认为tsql比osql更全功能,但同样的方法应该适用于。

创建一个shell脚本来包装tsql。把它放在你路上的某个地方。

然后将dbext配置值添加到.vimrc

" I'm using mssql.sh as the wrapper program. 
" Re-title to whatever you name yours

let g:dbext_default_SQLSRV_bin = "mssql.sh"

" FreeTDS options for osql/tsql are not as feature rich as dbext expects

let g:dbext_default_SQLSRV_cmd_options = ' '

" set 'host' in you profile to the FreeTDS server config, which will be altered in the script

我掀起的包装并没什么特别的,但经过测试和运作。

#!/bin/bash

# -S is better for FreeTDS then -H
options=$( echo $@ | sed -e 's/-H /-S /' -e 's/ -i.*//' )
# osql/tsql in freetds don't seem to accept a file flag
sql_scratch=$( echo $@ | sed 's|^.* -i||' )
# and execute...
cat $sql_scratch | tsql $options

答案 1 :(得分:0)

Osql附带了FreeTDS库,但可能会出现另一个错误:“非法选项-w”。

您可以在DBEXT连接中的type参数中使用ODBC而不是SQLSRV。 (另一种选择是使用DBI perl接口)

使用--with-iodbc选项安装iodbc并构建freetds。

编辑你的odbc.ini文件,你可以使用iodbc-config --iodbcini或find -name odbc.ini / |找到它。 grep odbc.ini。

我的工作odbc.ini(请注意文件名,我在freebsd盒子上):

[MYDNSNAME]
Driver          = /usr/local/lib/libtdsodbc.so
Description     = Sample OpenLink MT DSN
Server          = 192.168.100.4
Port            = 50436
TDS_Version     = 8.0
Database        = initial_db
ServerOptions   = 
ConnectOptions  = 
Options         = 
ReadOnly        = no

我在.vimrc上的dbext连接:

let g:dbext_default_profile_CONN = 'type=ODBC:dsnname=MYDSNNAME:user=domain\user:passwd=pass:dbname=initial_db'

答案 2 :(得分:0)

您还可以将DBExt配置为在freetds中使用更丰富的sqsh而不是osql程序。通过搜索“sqsh”,可以在:h dbext中找到执行此操作的示例连接配置文件。你当然应该已经有正常运作的sqsh。