linux 下OTL连接SQLServer非配置版
来源:互联网 发布:蓝翔高级技工学校知乎 编辑:程序博客网 时间:2024/05/08 09:04
在linux下连接sqlserver费了很多周折,关键是还不能配置,程序打包发出去就可以用,想想过了很多弯路,做次笔记也算是一些心得。
参考:http://my.oschina.net/xuhh/blog/173968?fromerr=TcxY6YSC
首先unixodbc和freetds是必须的,libiconv是一个转码的工具,可装可不装
我的linux系统版本是centos7.1,连接sqlseerver版本是MSSQL 2008,unixodbc资源
http://download.csdn.net/detail/mp295345033/9294067
freetds 资源:
http://share.weiyun.com/9cf07bfef09a8af69e8270cbda5058f7
安装unixodbc,解压后进入文件夹,
./configure --enable-gui=no ; make ; sudo make install
安装freetds:(不能在共享文件夹下安装,会报错!)
./configure --with-tdsver=7.3 --with-unixodbc=/usr/local --with-libiconv-prefix=/usr/local --enable-msdblib;make;make install
--with-tdsver: 是安装的版本,sqlserver必须指定7.3;
--with-unixodbc:是unixodbc的安装路径;
--with-libiconv-prefix:libconv的安装路径;
--enable-msdblib:允许连接SQLServer;
可能编译的时候还会有些错误,上网找找就可以解决了。
安装完成就可以用官方的例子测试了
<span style="color:#333333;">#include <iostream>using namespace std;#include <stdio.h>#define OTL_ODBC_MSSQL_2008 // Compile OTL 4/ODBC, MS SQL 2005#define OTL_FREETDS_ODBC_WORKAROUNDS // Enable the FreeTDS / ODBC workarounds for MS SQL#define OTL_ODBC//#define OTL_ODBC // Compile OTL 4/ODBC. Uncomment this when used with MS SQL 7.0/ 2000#define OTL_ODBC_UNIX // Compile OTL 4 / ODBC. Uncomment this when used in Linux / Unix#define OTL_STL#include "otlv4.h"otl_connect db; // connect object int main(){ otl_connect::otl_initialize(); // initialize ODBC environment try{ db.rlogon("Driver=/usr/local/lib/libtdsodbc.so;Host=192.168.1.1;Port=1433;tds version = 7.3;Server=192.168.1.1;Database=DATE;Uid=sa;Pwd=password",1); // 此处为链接时候的选项,必须带1 otl_cursor::direct_exec ( db, "drop table test_tab", otl_exception::disabled // disable OTL exceptions ); // drop table otl_cursor::direct_exec ( db, "create table test_tab(f1 int, f2 varchar(30))" ); // create table insert(); // insert records into table select(); // select records from table } catch(otl_exception& p){ // intercept OTL exceptions cerr<<p.msg<<endl; // print out error message cerr<<p.stm_text<<endl; // print out SQL that caused the error cerr<<p.sqlstate<<endl; // print out SQLSTATE message cerr<<p.var_info<<endl; // print out the variable that caused the error } db.logoff(); // disconnect from ODBC return 0;}</span>
- linux 下OTL连接SQLServer非配置版
- Linux下OTL连接Oracle数据库
- linux,windows下sqlserver连接配置
- linux otl 连接数据库
- linux 下连接 sqlserver
- Linux下Mysql_odbc的安装配置及OTL的使用
- VC下配置使用OTL
- Linux下python连接sqlserver
- Linux下otl调用MySQL数据库9.1版
- linux下SQLSERVER ODBC配置
- Ubuntu 下配置OTL 链接MySQL
- linux/freebsd下php连接ms sqlserver
- 用Linux下Perl脚本连接SQLServer
- linux 下用freetds 连接sqlserver
- Linux下使用OTL操作数据库
- OTL连接MySQL之unixODBC、mysql-connector-odbc安装配置
- VS2010下使用otl连接到oracle数据库
- SQLServer远程连接配置
- vector动态申请内存然后释放
- Problem - Slow PL/SQL procedure
- SD卡初始化以及命令详解
- Hibernate4 注解方式注意事项
- 《swift2.0 官方教程中文版》 第2章-02基本运算符
- linux 下OTL连接SQLServer非配置版
- Oracle Hint的用法
- adnroid 实现多样化布局及item横向滚动效果
- Android使用json与服务器交互
- @RequestMapping使用
- 为什么Git比SVN好
- 《swift2.0 官方教程中文版》 第2章-03字符串和字符
- Spring的JdbcTemplate、NamedParameterJdbcTemplate、SimpleJdbcTemplate
- Oracle左右连接