Golang SQLDriverConnect: {IM005} [MICROSOFT][ODBC Driver Manager] Driver Sqlallochandle on SQL_HANDLE_DBC failed

Source: Internet
Author: User
Tags driver manager
This is a creation in Article, where the information may have evolved or changed.

Problem:
2015/12/04 17:03:36 sqldb.go:2166:sqldriverconnect: {IM005} [MICROSOFT][ODBC Driver Manager] driver Sqlallochandle on SQL_ HANDLE_DBC failure

Environment: Go language writing
SQL SERVER Database
Packages used by the "CODE.GOOGLE.COM/P/ODBC" database operation

The program just started, running all right, but after a period of time, will always appear the above error message. Carefully review the printed error message, initially considered to be a database exception information.
Keep track of the database running, other programs connected to the database can be connected, troubleshooting database problems. However, the SQLDriverConnect reminder is clearly a reminder that the connection database failed. Suspect that there is a problem with the database connection pool.
To see the database connection for this application, the number of connections to the SQL Server database, the surprising discovery that there are more than 1000 connections, to see the detailed execution of the statement situation, found that the more than 1000 connections, in addition to a few connections of the other 1000 more are executed two statements. The same sentence notation

stmt, errs := Db.Prepare("select * from tbl")if errs!=nil {}defer stmt.Close()rows, err := stmt.Query()if err!=nil {}for rows.Next(){    varint    ifnil {        return value    }}

All the SQL is written in the same way, but why only these two statements will appear so many connections can not be released, to view the usage of data Prepare syntax, only unexpectedly found that the rows need to shut down, the other statements did not appear multi-connection situation is because, the other rows are finished loop, Rows are self-releasing if they are automatically cycled, or they need to be closed manually.

stmt, errs := Db.Prepare("select * from tbl")if errs!=nil {}defer stmt.Close()rows, err := stmt.Query()if err!=nil {}defer//必须手动关闭连接for rows.Next(){    varint    ifnil {        return value    }}

After the change, the program runs normally.

Related Article

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.