0

I am trying to access MS SQL server from python.

I installed pymssql and this is my code

import pymssql

conn = pymssql.connect(host='SAM-WOLPTP\SAM', user='SAM', password='password', database='test')

cur = conn.cursor()
cur.execute('CREATE TABLE persons(id INT, name VARCHAR(100))')
cur.executemany("INSERT INTO persons VALUES(%d, %s)", \
[ (1, 'John Doe'), (2, 'Jane Doe') ])
conn.commit()  # you must call commit() to persist your data if you don't set autocommit to True

conn.close()

While running the program I am getting this error:

pymssql.InterfaceError: Connection to the database failed for unknown reason

Alex K
  • 8,269
  • 9
  • 39
  • 57
user2728024
  • 1,496
  • 8
  • 23
  • 39
  • Check this. http://stackoverflow.com/questions/4150524/unable-to-connect-to-sql-server-via-pymssql – Stephen Lin Jan 09 '15 at 05:26
  • Thanks.. i tried that.. I believe it is a version problem. My SQL server is 64 bit but for pymssql 64 bit is not getting installed i tried with 32 bit its getting installed. – user2728024 Jan 09 '15 at 09:48

0 Answers0