<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar.g?targetBlogID\x3d4684235500622716427\x26blogName\x3dCaiwangqin\x27s+blog\x26publishMode\x3dPUBLISH_MODE_HOSTED\x26navbarType\x3dBLUE\x26layoutType\x3dCLASSIC\x26searchRoot\x3dhttp://blog.caiwangqin.com/search\x26blogLocale\x3dzh_CN\x26v\x3d2\x26homepageUrl\x3dhttp://blog.caiwangqin.com/\x26vt\x3d3393395200455623441', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe" }); } }); </script>

Caiwangqin's blog

Focus on Cloud Service, Smart Hardware, Architecture, Technic and beyond…

基于Debian 3.1 linux的Ruby on Rails ODBC安装配置过程

2006年9月10日星期日

1.   安装相关deb包


a)         Apt-get install unixodbc freedts-dev  (linux的ODBC驱动和 MS SQL and Sybase client library static libs and headers)


2.   配置ODBC DSN


a)         Vi  /etc/freetds/freedts.conf


添加下列信息:


[TEST-DB2]                       (自定义的数据库服务器名)


        host = 192.168.0.10       (数据库服务器的IP地址)


        port = 1433                (数据库服务器端口号)


        tds version =8.0


b)         vi /etc/odbc.ini


          


[TEST-DB2]                                         (DSN名)


Driver         =       /usr/lib/odbc/libtdsodbc.so    (一定要指定libdtsodbc.so的完全路径,否则ruby不能找到驱动)


#Setup        =      /usr/lib/odbc/libtdsS.so     


Server         =       192.168.0.10


Servername   =          TEST-DB2


Database      =       TESTBlog                    (指定缺省数据库)


#Port           =       1433


3.   运行 isql测试数据库连接


                     


 


apachtest:~# isql -v TEST-DB2 sa sa


+—————————————+


| Connected!                            |


|                                       |


| sql-statement                         |


| help [tablename]                      |


| quit                                  |


|                                       |


+—————————————+


SQL>


SQL> select count(*) from UserBlog


+————+


|            |


+————+


| 28239      |


+————+


1 rows affected


1 rows returned


SQL>


连接OK,注意,数据库名是大小写敏感的


 


4.         安装ruby1.8.2


Apt-get install irb   (会自动将ruby1.8.2装上,以及libdbi)


Apt-get install libodbc-ruby1.8   (安装ruby的odbc接口,自动安装好libodbc2)


Apt-get install libdbd-odbc-ruby


 


5.         运行irb


apachtest:~# irb


irb(main):001:0> require “dbi”


=> true


irb(main):002:0>  dbh=DBI.connect(’dbi:ODBC:TEST-DB2′,’sa’,’sa’)


=> #, @trace_mode=2, @handle=#>>irb(main):003:0>


 


返回正常信息OK


 


6.配置ruby


    Vi  config//database.yml:

development:

  adapter: sqlserver

  mode: odbc

  dsn: TEST-DB2

  username: sa

  password: sa

 


运行程序


 


目前ruby还有个问题没有解决,就是使用odbc_utf8时,ruby会报内存不足,然后程序中断,如果不使用UTF8,程序可以正常运行,但网页中不能提交中文内容!


 


该文章由carl.cao整理.


标签:

posted by Jesse Cai, 上午1:26

0 Comments:

发表评论

订阅 帖子评论 [Atom]

<< 主页