Thursday, December 22, 2011

MS SQL and Python

Had trouble connecting Python to MS SQL Server. Here is the answer!

MS-SQL and Python

In short:
  • Set up your ODBC Data Source Administrator
  • Insert Python code using very built in imports (dbi, odbc)

    Python code:

    import dbi
    import odbc

    query = "SELECT * FROM default_table";
    conn=odbc.odbc("odbc_data_source_admin_name");
    cursor = conn.cursor();
    cursor.execute(query);
    print (cursor.fetchall());
  • No comments:

    Post a Comment