Re: pyodbc connect string

Discussion in 'Python' started by Larry Martell, Apr 30, 2014.

  1. On Tue, Apr 29, 2014 at 7:09 PM, Chris Angelico <> wrote:
    > On Wed, Apr 30, 2014 at 10:57 AM, Larry Martell <> wrote:
    >> This works:
    >>
    >> pyodbc.connect('DRIVER=FreeTDS;' 'SERVER=xx.xx.xx.xx;' 'PORT=1433;'
    >> 'DATABASE=blah;' 'UID=foo;' 'PWD=bar;')
    >>
    >> But this does not:
    >>
    >> pyodbc.connect(conn_str)
    >>
    >> conn_str is constructed with:
    >>
    >> conn_str = "'DRIVER=%s;' 'SERVER=%s;' 'PORT=%s;' 'DATABASE=%s;'
    >> 'UID=%s;' 'PWD=%s;'" \
    >> % (RECIPE_DB['DRIVER'], RECIPE_DB['SERVER'],
    >> RECIPE_DB['PORT'], RECIPE_DB['DATABASE'],
    >> RECIPE_DB['USER'], RECIPE_DB['PASSWORD'])
    >>
    >> Anyone have any ideas as to why this doesn't work.

    >
    > Start by printing out conn_str. That'll tell you if it's actually
    > coming out the way you think it is. I can see where the problem
    > probably is (assuming these are faithful copy/pastes), in the form of
    > an extra double quote; but actually print them out and see what you're
    > getting.


    When I print conn_str out it does not have the double quotes, But I
    was able to solve this by doing this:

    pyodbc.connect('DRIVER=' + RECIPE_DB['DRIVER'] + ';' + 'SERVER=' +
    RECIPE_DB['SERVER'] + ';' + 'PORT=' + RECIPE_DB['PORT'] + ';' +
    'DATABASE=' + RECIPE_DB['DATABASE'] + ';' + 'UID=' + RECIPE_DB['USER']
    + ';' + 'PWD=' + RECIPE_DB['PASSWORD'] + ';')

    '
    Thanks.
     
    Larry Martell, Apr 30, 2014
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. timw.googlepost

    installing pyodbc

    timw.googlepost, Apr 11, 2006, in forum: Python
    Replies:
    0
    Views:
    363
    timw.googlepost
    Apr 11, 2006
  2. iMath
    Replies:
    1
    Views:
    954
    Dennis Lee Bieber
    Oct 17, 2012
  3. Larry Martell

    pyodbc connect string

    Larry Martell, Apr 30, 2014, in forum: Python
    Replies:
    0
    Views:
    58
    Larry Martell
    Apr 30, 2014
  4. Chris Angelico

    Re: pyodbc connect string

    Chris Angelico, Apr 30, 2014, in forum: Python
    Replies:
    0
    Views:
    59
    Chris Angelico
    Apr 30, 2014
  5. Larry Martell

    Re: pyodbc connect string

    Larry Martell, Apr 30, 2014, in forum: Python
    Replies:
    0
    Views:
    62
    Larry Martell
    Apr 30, 2014
Loading...

Share This Page