Python Forum
ODBC TO microsoft sql server 2014
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ODBC TO microsoft sql server 2014
#1
hello,
please help!

i am soo frustrated...

what am i doing wrong?

import pyodbc
server = 'SQLEXPRESS'
database = 'TSQL2012'
username = 'user'
password = 'pass'
driver= '{ODBC Driver 11 for SQL Server}'
cnxn = pyodbc.connect('DRIVER='+driver+';PORT=1433;SERVER='+server+';PORT=1443;DATABASE='+database+';UID='+username+';PWD='+ password)
cursor = cnxn.cursor()
cursor.execute("select * from [Production].[Categories]")
row = cursor.fetchone()
if row:
   print row
Error:
C:\Python27\python.exe C:/Users/Papom/PycharmProjects/untitled/ODBC.py Traceback (most recent call last):   File "C:/Users/Papom/PycharmProjects/untitled/ODBC.py", line 7, in <module>     cnxn = pyodbc.connect('DRIVER='+driver+';PORT=1433;SERVER='+server+';PORT=1443;DATABASE='+database+';UID='+username+';PWD='+ password) pyodbc.Error: ('08001', '[08001] [Microsoft][ODBC Driver 11 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [53].  (53) (SQLDriverConnect); [HYT00] [Microsoft][ODBC Driver 11 for SQL Server]Login timeout expired (0); [01S00] [Microsoft][ODBC Driver 11 for SQL Server]Invalid connection string attribute (0); [08001] [Microsoft][ODBC Driver 11 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. (53)') Process finished with exit code 1
Output:
[b][u]odbc[/u][/b] Microsoft ODBC Driver for SQL Server Version 12.00.2000 Running connectivity tests... Attempting connection Connection established Verifying option settings Disconnecting from server TESTS COMPLETED SUCCESSFULLY!
Moderator Larz60+: Removed formatting, added tags - Pease read how to post
see: https://python-forum.io/misc.php?action=help&hid=25
Reply
#2
Clean up your post if you want help.
Not sure anyone wants to deal with this mess.
Reply
#3
I'd love to do this, but I do not know how to do that....
Reply
#4
I don't think this is related to your issue, but why are you using version 11? Isn't 13 the newest?

Do you need to create an odbc connection? https://docs.microsoft.com/en-us/sql/odb...inistrator
Do you have the odbc drivers installed? (just the python package isn't enough) https://www.microsoft.com/en-us/download...x?id=50420
Can you access the database from an external program, to verify you have the right connection info? Microsoft SQL Management Studio is a good way to quickly check.
Reply
#5
hey

i fix it with ODBC driver 11 for sql server
and add this line code: "Trusted_Connection=Yes" to the pyodbc.connect object

10x for the hlp
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Paramiko Server -- Exception (server): Error reading SSH protocol banner ujlain 3 4,480 Jul-24-2023, 06:52 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020