How to connect to MS SQLServer using Vim dbext on Mac OSX?
I use MacVim and the dbext plugin to connect to Oracle and it works well. Now I need to connect to MS SQLServer, but it showed error:
Connection: T(S开发者_如何转开发QLSRV) H(localhost) U(user) at 14:38
/bin/bash: osql: command not found
Anyone know how to do this?
Make sure you have one of the FreeTDS CLI programs. I think tsql is more full featured then osql, but the same approach should work with either.
Create a shell script to wrap tsql. Put it somewhere in your path.
Then add the dbext config values to your .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
The wrapper I whipped up is nothing special, but it's tested and works.
#!/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
Osql comes with the library of FreeTDS, but probably another error will be prompted: "Illegal option -w".
You can use ODBC instead of SQLSRV in the type parameter in the connection of DBEXT. (The other option being using DBI perl interface)
Install iodbc and build freetds with the --with-iodbc option.
Edit your odbc.ini file, you may find it using iodbc-config --iodbcini or find -name odbc.ini / | grep odbc.ini.
My working odbc.ini (please take care with file names, im on a freebsd box):
[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
And my dbext connection on .vimrc:
let g:dbext_default_profile_CONN = 'type=ODBC:dsnname=MYDSNNAME:user=domain\user:passwd=pass:dbname=initial_db'
You can also configure DBExt to use the richer sqsh instead of the osql program in freetds. An example connection profile that does so can be found in :h dbext
by searching for "sqsh". You should of course already have sqsh in working order.
精彩评论