title: Unable to connect to MS-SQL with ISQL
body: <p>First post on StackExchange - please go easy :)</p>
  
  <p>I have setup ODBC in Centos 6 in order to perform ms-sql queries from my Asterisk installation. </p>
  
  <p>My Config files are:</p>
  
  <p>/etc/odbc.ini</p>
  
  <pre><code>[asterisk-connector]
  Description     = MS SQL connection to 'asterisk' database
  Driver          = /usr/lib64/libtdsodbc.so
  Setup           = /usr/lib64/libtdsS.so
  Servername      = SQL2
  Port            = 1433
  Username        = MyUsername
  Password        = MyPassword
  TDS_Version     = 7.0
  </code></pre>
  
  <p>/etc/odbcinst.ini</p>
  
  <pre><code>[odbc-test]
  Description = TDS connection
  Driver = /usr/lib64/libtdsodbc.so
  Setup = /usr/lib64/libtdsS.so
  UsageCount = 1
  FileUsage = 1
  </code></pre>
  
  <p>/etc/asterisk/res_odbc.conf</p>
  
  <pre><code>[asterisk-connector]
  enabled =&gt; yes
  dsn =&gt; asterisk-connector
  username =&gt; MyUsername
  password =&gt; MyPassword
  pooling =&gt; no
  limit =&gt;
  pre-connect =&gt; yes
  </code></pre>
  
  <p>I am able to connect via ISQL when I pass in the password and username:</p>
  
  <pre><code>[root@TestVM etc]# isql -v asterisk-connector MyUsername MyPassword
  +---------------------------------------+
  | Connected!                            |
  |                                       |
  | sql-statement                         |
  | help [tablename]                      |
  | quit                                  |
  |                                       |
  +---------------------------------------+
  SQL&gt;
  </code></pre>
  
  <p>..but I should be able to connect without the username / password. All that returns is:</p>
  
  <pre><code>[root@TestVM etc]# isql -v asterisk-connector
  [S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source
  [01000][unixODBC][FreeTDS][SQL Server]Adaptive Server connection failed
  [ISQL]ERROR: Could not SQLConnect
  </code></pre>
  
  <p>It is as if ISQL cannot read the username and password from the config files.</p>
  
  <p>I need to be able to perform MS-SQL lookups from within the Asterisk dialplan, but for that to happen I must be able to call ISQL with just the data source name and can't pass in the authentication parameters.</p>
  
  <p>All the guides I've read online state that I should be able to connect with just the </p>
  
  <pre><code>isql -v asterisk-connector
  </code></pre>
  
  <p>command, but that's not happening for me. </p>
  
  <p>I've been pulling my hair out for a few days on this, so any help or pointers in the right direction would be much appreciated. </p>
  
  <p>Thanks in advance.</p>
  
  <p>Edit:</p>
  
  <p>I have turned on logging, and may have a clue. The username and password definitely aren't being passed in. Look:</p>
  
  <pre><code>[ODBC][27557][1455205133.129690][SQLConnect.c][3614]
                  Entry:
                          Connection = 0xac3080
                          Server Name = [asterisk-connector][length = 18 (SQL_NTS)]
                          User Name = [NULL]
                          Authentication = [NULL]
                  UNICODE Using encoding ASCII 'ISO8859-1' and UNICODE 'UCS-2LE'
  
                  DIAG [01000] [FreeTDS][SQL Server]Adaptive Server connection failed
  
                  DIAG [S1000] [FreeTDS][SQL Server]Unable to connect to data source
  </code></pre>
  
  <p>So User Name and Authentication here are [NULL]. It's obviously not picking up the username / password in odbc.ini or res_odbc.conf, but the question is why. I'll keep investigating :)</p>
  
  <p>Edit2:</p>
  
  <p>The OSQL utility returns:</p>
  
  <pre><code>[root@TestVM etc]# osql -S SQL2 -U MyUsername -P MyPassword
  checking shared odbc libraries linked to isql for default directories...
  strings: '': No such file
          trying /tmp/sqlH ... no
          trying /tmp/sqlL ... no
          trying /etc ... OK
  checking odbc.ini files
          reading /root/.odbc.ini
  [SQL2] not found in /root/.odbc.ini
          reading /etc/odbc.ini
  [SQL2] found in /etc/odbc.ini
  found this section:
  looking for driver for DSN [SQL2] in /etc/odbc.ini
    no driver mentioned for [SQL2] in odbc.ini
  looking for driver for DSN [default] in /etc/odbc.ini
  osql: error: no driver found for [SQL2] in odbc.ini
  </code></pre>