pyodbc

What's causing 'unable to connect to data source' for pyodbc?

二次信任 提交于 2019-11-30 12:33:34
问题 I'm trying to connect to an MSSQL database from python on Linux (SLES). I have installed pyodbc and Free TDS. From the command line: tsql -H server -p 1433 -U username -P password Connects to the server without a problem, however, from Python: import pyodbc pyodbc.connect(driver='{FreeTDS}', server='server', database='database', uid='username', pwd='password') Yields an error: pyodbc.Error: ('08001', '[08001] [unixODBC][FreeTDS][SQL Server]Unable to connect to data source (0)

Using pyodbc cause error: Data source name not found and no default driver specified

余生长醉 提交于 2019-11-30 09:05:29
问题 I'm using pyodbc to connect SQL Server. I had created connection string like this: from sqlalchemy import Table, Column, databases, Integer, String, ForeignKey, create_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import session engine = create_engine('mssql+pyodbc://sa:123@localhost/TrainQuizDB') engine.connect() TrainQuizDB is database name that I created in Sql Server. For more information I have windows 8.1 64bit and I installed python version 3.5.1

make python wait for stored procedure to finish executing

允我心安 提交于 2019-11-30 09:05:25
I have a python script that uses pyodbc to call an MSSQL stored procedure, like so: cursor.execute("exec MyProcedure @param1 = '" + myparam + "'") I call this stored procedure inside a loop, and I notice that sometimes, the procedure gets called again before it was finished executing the last time. I know this because if I add the line time.sleep(1) after the execute line, everything works fine. Is there a more elegant and less time-costly way to say, "sleep until the exec is finished"? Update (Divij's solution): This code is currently not working for me: from tornado import gen import pyodbc

basic pyodbc bulk insert

不问归期 提交于 2019-11-30 08:47:28
In a python script, I need to run a query on one datasource and insert each row from that query into a table on a different datasource. I'd normally do this with a single insert/select statement with a tsql linked server join but I don't have a linked server connection to this particular datasource. I'm having trouble finding a simple pyodbc example of this. Here's how I'd do it but I'm guessing executing an insert statement inside a loop is pretty slow. result = ds1Cursor.execute(selectSql) for row in result: insertSql = "insert into TableName (Col1, Col2, Col3) values (?, ?, ?)" ds2Cursor

PyODBC : can't open the driver even if it exists

℡╲_俬逩灬. 提交于 2019-11-30 08:22:18
I'm new to the linux world and I want to query a Microsoft SQL Server from Python. I used it on Windows and it was perfectly fine but in Linux it's quite painful. After some hours, I finally succeed to install the Microsoft ODBC driver on Linux Mint with unixODBC. Then, I set up an anaconda with python 3 environment. I then do this : import pyodbc as odbc sql_PIM = odbc.connect("Driver={ODBC Driver 13 for SQL Server};Server=XXX;Database=YYY;Trusted_Connection=Yes") It returns : ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib '/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.0.so.0.0'

Python multiprocessing and database access with pyodbc “is not safe”?

只谈情不闲聊 提交于 2019-11-30 08:07:46
问题 The Problem: I am getting the following traceback and don't understand what it means or how to fix it: Traceback (most recent call last): File "<string>", line 1, in <module> File "C:\Python26\lib\multiprocessing\forking.py", line 342, in main self = load(from_parent) File "C:\Python26\lib\pickle.py", line 1370, in load return Unpickler(file).load() File "C:\Python26\lib\pickle.py", line 858, in load dispatch[key](self) File "C:\Python26\lib\pickle.py", line 1083, in load_newobj obj = cls._

pyodbc the sql contains 0 parameter markers but 1 parameters were supplied' 'hy000'

倖福魔咒の 提交于 2019-11-30 07:14:33
问题 I am using Python 3.6, pyodbc, and connect to SQL Server. I am trying make connection to a database, then creating a query with parameters. Here is the code: import sys import pyodbc # connection parameters nHost = 'host' nBase = 'base' nUser = 'user' nPasw = 'pass' # make connection start def sqlconnect(nHost,nBase,nUser,nPasw): try: return pyodbc.connect('DRIVER={SQL Server};SERVER='+nHost+';DATABASE='+nBase+';UID='+nUser+';PWD='+nPasw) print("connection successfull") except: print (

pyodbc and mySQL

南笙酒味 提交于 2019-11-30 04:55:20
问题 I am unable to connect to mySQl db using pyodbc. Here is a snippet of my script: import pyodbc import csv cnxn = pyodbc.connect("DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost;DATABASE=mydb; UID=root; PASSWORD=thatwouldbetelling;") crsr = cnxn.cursor() with open('C:\\skunkworks\\archive\\data\\myfile.csv','r') as myfile: rows = csv.reader(myfile, delimiter=',', quotechar='"') for row in rows: insert_str = 'INSERT into raw_data VALUES(something, something)' print insert_str #crsr.execute

PYODBC to Pandas - DataFrame not working - Shape of passed values is (x,y), indices imply (w,z)

江枫思渺然 提交于 2019-11-30 03:45:07
I used pyodbc with python before but now I have installed it on a new machine ( win 8 64 bit, Python 2.7 64 bit, PythonXY with Spyder). Before I used to (at the bottom you can find more real examples): columns = [column[0] for column in cursor.description] temp = cursor.fetchall() data = pandas.DataFrame(temp,columns=columns) and it would work fine. Now it seems like DataFrame is not able to convert from the data fetched from the cursor anymore. It returns: Shape of passed values is (x,y), indices imply (w,z) I kind of see where the issue is. Basically, imagine I fetch only one row. Then

pyodbc.connect timeout argument is ignored for calls to SQL Server

偶尔善良 提交于 2019-11-30 03:44:09
问题 I am using pyodbc on Linux with FreeTDS to connect to SQL Server 2005. I have noticed that the timeout argument to my connection is not being honoured by my queries. When I run the following I would expect to see timeout errors after both cursor.execute calls. import pyodbc import time connString = 'SERVER=dbserver;PORT=1433;DATABASE=db;UID=dbuser;PWD=dbpwd;' + \ 'DRIVER=FreeTDS' cnxn = pyodbc.connect(connString , timeout=3) cursor = cnxn.cursor() t1 = time.time() cursor.execute("SELECT MAX