Ubuntu 14.04 ODBC Configuration

Source: Internet
Author: User
Tags dsn stmt

In order to be able to use Linux under the Golang environment to connect SQL Server 2008 to check a lot of data, eventually using UNIXODBC FreeTDS and other connections successfully.

Run the following shell

#!/bash/bin
sudo apt-get update && sudo apt-get upgrade-y
sudoApt-getInstallUnixodbc unixodbc-bin Unixodbc-dev freetds-bin freetds-dev TDSODBC-yEcho "================================================================="Echo "[FreeTDS]Description = FreeTDS Driver v0. theDriver=/usr/lib/x86_64-linux-gnu/odbc/Libtdsodbc.sosetup=/usr/lib/x86_64-linux-gnu/odbc/Libtdss.sofileusage=1Dontdlclose=1Usagecount=1Client CharSet=utf-8"| sudo tee-a/etc/odbcinst.iniEcho "[TestDB]Driver =freetdsdescription=My Test servertrace=Noservername=Demosql # This corresponds to the name in the following freetds.conf port=1433Database=Db_demo # Modify the name of the database you need to connect to tds_version=7.2"
| sudo tee-a/etc/odbc.iniEcho "[Demosql]Host =192.168.1.1#这里填写自己的数据库地址Port=1433TDS Version=7.2 # Connection sql2008, according to FreeTDS official website, can use version 7.2
#http://www.freetds.org/userguide/choosingtdsprotocol.htm
"| sudo tee-a/etc/freetds/freetds.confEcho "================================================================="Echo "isql-v testdb username passwd"

Connect test with ISQL-V DSN name username password after completion

Download the ODBC package required for go after the test is successful

Go get-v-u github.com/weigj/go-odbc

Next, write a test program:

Package Mainimport ("FMT" "GITHUB.COM/WEIGJ/GO-ODBC") func main () {conn, _: = ODBC. Connect ("DSN=TESTDB; Uid=sa; Pwd=password ") stmt, _: = conn. Prepare ("SELECT top * from Studentinfo") stmt. Execute () rows, _: = stmt. Fetchall () for I, row: = Range rows {fmt. Println (i, Row)}stmt. Close () Conn. Close ()}

Results:

[' Run ' | Done: -. 224378ms]0&{[ -]}    1&{[ at]}    2&{[ the]}    3&{[ at]}    4&{[ -]}    5&{[ -]}    6&{[ +]}    7&{[ the]}    8&{[ *]}    9&{[ -]}

Ubuntu 14.04 ODBC Configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.