# Error! Unable to retrieve database handle. CDR failed

**URL:** <https://community.asterisk.org/t/error-unable-to-retrieve-database-handle-cdr-failed/71017>\
**Category:** Asterisk Support\
**Created:** [June 13, 2017, 5:55am UTC](https://community.asterisk.org/t/error-unable-to-retrieve-database-handle-cdr-failed/71017 "2017-06-13T05:55:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rezuan\_cse](https://avatars.discourse-cdn.com/v4/letter/r/46a35a/32.png) [@rezuan\_cse](https://community.asterisk.org/u/rezuan_cse)\
**Post date:** [June 13, 2017, 5:55am UTC](https://community.asterisk.org/t/error-unable-to-retrieve-database-handle-cdr-failed/71017/1 "2017-06-13T05:55:01Z")

</div>

Hi,

I’m facing an issue with asterisk `cdr` table. Data is inserting successfully after call hangup. But the issue, I’m getting this below error.

`[Jun 13 11:04:02] ERROR[18294]: cdr_odbc.c:175 odbc_log: Unable to retrieve database handle. CDR failed.`

Below settings I’ve made in my config files. What’s wrong is going here? Can anyone have any idea?

**/etc/asterisk/cdr\_mysql.conf**

```auto
[global]
hostname=localhost
dbname=asterisk
table=cdr
password=xxxx
user=xxxx

```

**/etc/odbc.ini**

```auto
[MySQL-asterisk]
Description = MySQL ODBC Driver Testing
Driver = MySQL
Socket = /var/run/mysqld/mysqld.sock
Server = localhost
User = xxxx
Password = xxxx
Database = asterisk

```

**/etc/asterisk/cdr\_odbc.conf**

```auto
[global]
dsn=MySQL-asterisk
username=xxxx
password=xxxx
loguniqueid=yes
dispositionstring=yes

```

Nothing I’ve change in `res_odbc.conf`

**/etc/asterisk/cdr\_adaptive\_odbc.conf**

```auto
[adaptive_connection]
connection=asterisk
table=cdr

```

**Note that my server config:**  
Asterisk 13.16.0  
CentOS Linux release 7.3.1611 (Core)

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![rezuan\_cse](https://avatars.discourse-cdn.com/v4/letter/r/46a35a/32.png) [@rezuan\_cse](https://community.asterisk.org/u/rezuan_cse)\
**Post date:** [June 13, 2017, 6:18am UTC](https://community.asterisk.org/t/error-unable-to-retrieve-database-handle-cdr-failed/71017/2 "2017-06-13T06:18:12Z")

</div>

@jcolp can you have a look please if you are available. Sorry for tagging you.

---

<div class="post-metadata">

**Author:** ![jcolp](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/jcolp/32/8848_2.png) [@jcolp](https://community.asterisk.org/u/jcolp)\
**Post date:** [June 13, 2017, 9:26am UTC](https://community.asterisk.org/t/error-unable-to-retrieve-database-handle-cdr-failed/71017/3 "2017-06-13T09:26:06Z")

</div>

When you posted this it was 3AM my time so tagging me wasn’t really needed. In fact I generally already respond to any posts which I have knowledge on.

If you haven’t changed anything in res\_odbc.conf then your configuration is incomplete, as it is explicitly disabled in that file by default.

---

<div class="post-metadata">

**Author:** ![rezuan\_cse](https://avatars.discourse-cdn.com/v4/letter/r/46a35a/32.png) [@rezuan\_cse](https://community.asterisk.org/u/rezuan_cse)\
**Post date:** [June 13, 2017, 9:28am UTC](https://community.asterisk.org/t/error-unable-to-retrieve-database-handle-cdr-failed/71017/4 "2017-06-13T09:28:04Z")

</div>

Thanks for the response. I’m really apologies for tagging you.  
I’m checking and updating the res\_odbc.conf file.

---

<div class="post-metadata">

**Author:** ![jeanne](https://avatars.discourse-cdn.com/v4/letter/j/3da27b/32.png) [@jeanne](https://community.asterisk.org/u/jeanne)\
**Post date:** [June 13, 2017, 9:43am UTC](https://community.asterisk.org/t/error-unable-to-retrieve-database-handle-cdr-failed/71017/5 "2017-06-13T09:43:38Z")

</div>

Hi,

Maybe this tutorial can help You [http://www.minestron.it/node/352](http://www.minestron.it/node/352).

---

<div class="post-metadata">

**Author:** ![rezuan\_cse](https://avatars.discourse-cdn.com/v4/letter/r/46a35a/32.png) [@rezuan\_cse](https://community.asterisk.org/u/rezuan_cse)\
**Post date:** [June 13, 2017, 10:37am UTC](https://community.asterisk.org/t/error-unable-to-retrieve-database-handle-cdr-failed/71017/6 "2017-06-13T10:37:04Z")

</div>

Thank you @jeanne. The problem has been resolved from your given link. 🙂

---

<div class="post-metadata">

**Author:** ![Hamza7](https://avatars.discourse-cdn.com/v4/letter/h/c0e974/32.png) [@Hamza7](https://community.asterisk.org/u/Hamza7)\
**Post date:** [December 25, 2017, 9:25am UTC](https://community.asterisk.org/t/error-unable-to-retrieve-database-handle-cdr-failed/71017/7 "2017-12-25T09:25:38Z")

</div>

Hi,  
I followed The link that @jeanne posted, but with no luck!  
Some times the call get stored in CDR table, but some other times I get the error : Unable to retrieve database handle. CDR failed. !!  
Any help ?

---

<div class="post-metadata">

**Author:** ![AtronSeige](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/atronseige/32/3954_2.png) [@AtronSeige](https://community.asterisk.org/u/AtronSeige)\
**Post date:** [September 20, 2019, 7:18am UTC](https://community.asterisk.org/t/error-unable-to-retrieve-database-handle-cdr-failed/71017/8 "2019-09-20T07:18:16Z")

</div>

What I learnt on how to resolve this error:  
The DSN name in /etc/asterisk/cdr\_odbc.conf must point to the section name in /etc/asterisk/res\_odbc.conf.  
The DSN name in /etc/asterisk/res\_odbc.conf must point to the section name in /etc/odbc.ini  
The Driver name in /etc/odbc.ini must point to the section name in /etc/odbcinst.ini

I hope this helps someone.
