Animate_Ant
Animate_Ant

Reputation: 80

Error while connecting to the Sql Server with pyodbc

I'm trying to fetch data from SQL database with pyodbc with the code given below.The connection works rarely, most of the time it gives the error,

OperationalError: ('HYT00', '[HYT00] [Microsoft][ODBC SQL Server Driver]Login timeout expired (0) (SQLDriverConnect)')

import numpy as np
import pyodbc as odbc

conn_string = ('DRIVER={SQL Server};SERVER=test;DATABASE=DEV;UID=me;PWD=whatever;')
cnxn = odbc.connect(conn_string)
cursor = cnxn.cursor()
cursor.execute("Select * from PurchaseOrders")
rows = cursor.fetchall()
ID = [i[1] for i in rows]
ID_array = np.fromiter(ID, dtype= np.int32)

I have tried setting the timeout to zero and DRIVER={ODBC Driver 11 for SQL Server} as I'm using SQL Server 2014. None of these works.

Upvotes: 0

Views: 2218

Answers (1)

Animate_Ant
Animate_Ant

Reputation: 80

There was a problem with DNS. I used the IP address of the server instead, works fine now.

Upvotes: 1

Related Questions