title: Using Oracle Service Names with SQLAlchemy
body: <p>I've run into a nasty little problem connecting to an Oracle schema via SQLAlchemy using a service name. Here is my code as a script. (items between angle brackets are place holders for real values for security reasons)</p>
  
  <pre><code>from sqlalchemy import create_engine
  
  if __name__ == "__main__":                                                                                                                                                        
      engine = create_engine("oracle+cx_oracle://&lt;username&gt;:&lt;password&gt;@&lt;host&gt;/devdb")                                                                                                                                                   
      result = engine.execute("create table test_table (id NUMBER(6), name VARCHAR2(15) not NULL)")
      result = engine.execute("drop table test_table")
  </code></pre>
  
  <p>Where 'devdb' is a service name and not an SID. The result of running this script is the stack trace.</p>
  
  <pre><code>(oracle-test)[1]jgoodell@jgoodell-MBP:python$ python example.py 
  Traceback (most recent call last):
    File "example.py", line 8, in &lt;module&gt;
      result = engine.execute("create table test_table (id NUMBER(6), name VARCHAR2(15) not NULL)")
    File "/Users/jgoodell/.virtualenvs/oracle-test/lib/python2.6/site-packages/sqlalchemy/engine/base.py", line 1621, in execute
      connection = self.contextual_connect(close_with_result=True)
    File "/Users/jgoodell/.virtualenvs/oracle-test/lib/python2.6/site-packages/sqlalchemy/engine/base.py", line 1669, in contextual_connect
      self.pool.connect(),
    File "/Users/jgoodell/.virtualenvs/oracle-test/lib/python2.6/site-packages/sqlalchemy/pool.py", line 272, in connect
      return _ConnectionFairy(self).checkout()
    File "/Users/jgoodell/.virtualenvs/oracle-test/lib/python2.6/site-packages/sqlalchemy/pool.py", line 425, in __init__
      rec = self._connection_record = pool._do_get()
    File "/Users/jgoodell/.virtualenvs/oracle-test/lib/python2.6/site-packages/sqlalchemy/pool.py", line 777, in _do_get
      con = self._create_connection()
    File "/Users/jgoodell/.virtualenvs/oracle-test/lib/python2.6/site-packages/sqlalchemy/pool.py", line 225, in _create_connection
      return _ConnectionRecord(self)
    File "/Users/jgoodell/.virtualenvs/oracle-test/lib/python2.6/site-packages/sqlalchemy/pool.py", line 318, in __init__
      self.connection = self.__connect()
    File "/Users/jgoodell/.virtualenvs/oracle-test/lib/python2.6/site-packages/sqlalchemy/pool.py", line 368, in __connect
      connection = self.__pool._creator()
    File "/Users/jgoodell/.virtualenvs/oracle-test/lib/python2.6/site-packages/sqlalchemy/engine/strategies.py", line 80, in connect
      return dialect.connect(*cargs, **cparams)
    File "/Users/jgoodell/.virtualenvs/oracle-test/lib/python2.6/site-packages/sqlalchemy/engine/default.py", line 279, in connect
      return self.dbapi.connect(*cargs, **cparams)
  sqlalchemy.exc.DatabaseError: (DatabaseError) ORA-12505: TNS:listener does not currently know of SID given in connect descriptor
   None None
  </code></pre>
  
  <p>If 'devdb' were an SID and not a service name this example would work just fine, I've been trying different permutations of the connection string but haven't found anything that works. There also does not appear to be anything in the SQLAlchemy documentation that explicitly explains how to handle SID's verses service names for Oracle connections.</p>