SQLServer/Python Connection

I go into an IDLE session and try to connect to SQLServer 2008 Express:
import pymssql
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import pymssql
  File "C:\Python34\pymssql.py", line 3, in <module>
    conn = pymssql.connect(server="A117078\SQLEXPRESS", user="sa", password="master", database="tempdb")
AttributeError: 'module' object has no attribute 'connect'
>>> import pymssql
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    import pymssql
  File "C:\Python34\pymssql.py", line 3, in <module>
    conn = pymssql.connect(server="A117078\SQLEXPRESS", user="sa", password="master", database="tempdb")
AttributeError: 'module' object has no attribute 'connect'
>>> import pymssql
>>> conn = pymssql.connect(host='localhost', user='sa', password='master', database='tempdb')
Traceback (most recent call last):
  File "pymssql.pyx", line 630, in pymssql.connect (pymssql.c:10097)
  File "_mssql.pyx", line 1887, in _mssql.connect (_mssql.c:20477)
  File "_mssql.pyx", line 631, in _mssql.MSSQLConnection.__init__ (_mssql.c:6156)
  File "_mssql.pyx", line 1612, in _mssql.maybe_raise_MSSQLDatabaseException (_mssql.c:16426)
_mssql.MSSQLDatabaseException: (20009, b'DB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is unavailable or does not exist\nNet-Lib error during Unknown error (10035)\n')


What do i need to do to make Adaptive Server available???
xoxomosAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pcelbaCommented:
I've tested pymssql in Python 2.7 and it also does not work for me under Windows 7...

But I'll test it under Python 3.x and let you know. Documentation and samples are available here: http://pymssql.org/en/latest/

pymssql does not seem to be Windows compatible module... But I did not test everything described here: http://pymssql.sourceforge.net/architecture.php yet.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pcelbaCommented:
Update:  Python is supported language in Visual Studio 2013 and newer, so it could be worth to try...

Also it should be possible to connect via ODBC driver:
import pyodbc
cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=localhost;DATABASE=testdb;UID=me;PWD=pass')
cursor = cnxn.cursor()
cursor.execute("select user_id, user_name from users")
rows = cursor.fetchall()
for row in rows:
    print row.user_id, row.user_name

Open in new window

See the code source for more details.
0
zozimosCommented:
Big thanks!!.  I'll put a sqlserver and python on this laptop tonight and try the change in authentication method first.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

xoxomosAuthor Commented:
Just tried the Visual Studio 2013 Express with the same results.   However there are two older versions of Visual Studio that came with this desktop and I'm mulling over possibly removing them.
0
xoxomosAuthor Commented:
Looking in the module

pymssql.pyx  line 573

try:
        conn = _mssql.connect(server, user, password, charset, database,  appname, port)
Here there are seven parameters to be passes
however the example shows only four parameters
conn = pymssql.connect(host='134.154.228.217', user='sa', password='master', database='master')
Is this the reason the script bombs?
0
pcelbaCommented:
Probably not but you may try to pas some AppName (any text string) and port number which is 1433 obviously. Charset value is questionable.
0
xoxomosAuthor Commented:
Actually i get character set (default) from running tsql command.
C:\freetds-0.95rc2\bin>tsql -H localhost\SQLEXPRESS -U sa -p 1433
Password: Indigen0us

locale is "English_United States.1252"
using default charset "UTF-8"


It just hangs.
Same results when I use it.
0
xoxomosAuthor Commented:
Thanks.  In my case the problem was sqlserver was not running on the 1433 but got assigned dynamically.  Something like 52000.  Once i went into config manager and changed it to 1433 stuff worked.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Python

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.