pyodbc

sql.h not found when installing PyODBC on Heroku

为君一笑 提交于 2019-11-28 08:00:39
I'm trying to install PyODBC on Heroku, but I get fatal error: sql.h: No such file or directory in the logs when pip runs. How do I fix this error? To follow up on the answer below... Example for Ubuntu: sudo apt-get install unixodbc unixodbc-dev Example for CentOS: sudo yum install unixODBC-devel On Windows: conn = pyodbc.connect('DRIVER={SQL Server};SERVER=yourserver.yourcompany.com;DATABASE=yourdb;UID=user;PWD=password') On Linux: conn = pyodbc.connect('DRIVER={FreeTDS};SERVER=yourserver.yourcompany.com;PORT=1433;DATABASE=yourdb;UID=user;PWD=password;TDS_VERSION=7.2') You need the unixODBC

Pyodbc error Data source name not found and no default driver specified paradox

∥☆過路亽.° 提交于 2019-11-28 06:55:14
I am attempting to use pyobdc to read data from a paradox database, and I keep getting the following error when attempting to connect to the database: pyodbc.Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)') I have tried to create new DNS links for the database but it has not helped what so ever. My system links looks like this: My code is: import os import sys import time import pyodbc LOCATION = "c:\Users\Marcello\Desktop\DATA\ScorMonitor.db" cnxn = pyodbc.connect(r"Driver={{Microsoft Paradox Driver

return column names from pyodbc execute() statement

淺唱寂寞╮ 提交于 2019-11-28 05:47:18
from pandas import DataFrame import pyodbc cnxn = pyodbc.connect(databasez) cursor.execute("""SELECT ID, NAME AS Nickname, ADDRESS AS Residence FROM tablez""") DF = DataFrame(cursor.fetchall()) This is fine to populate my pandas DataFrame. But how do I get DF.columns = ['ID', 'Nickname', 'Residence'] straight from cursor ? Is that information stored in cursor at all? You can get the columns from the cursor description: columns = [column[0] for column in cursor.description] phoenix10k Recent pandas have a higher level read_sql functions that can do this for you import pyodbc import pandas as pd

pyodbc can't connect to database

别等时光非礼了梦想. 提交于 2019-11-28 05:21:12
问题 I'm using pyodbc library from here and I'm connecting this way: conn = pyodbc.connect(r'DRIVER={SQL Server Native Client 11.0};Server=(localdb)\MSSQLLocalDB;Integrated Security=true; database = online_banking; autocommit = True') I use MSSQLLocalDB because it's the default instance name for SQL Server 2014. And this last version of Python 2.7. However I cant run any simple query, every if them raise the error, saying that there is no such object or in that particular case database: cursor

Cannot perform a backup or restore operation within a transaction

南笙酒味 提交于 2019-11-28 04:35:23
问题 I am using PyODBC to back up my database, using following code: SQL_command = """ BACKUP DATABASE [MyDatabase] TO DISK = N'D:\MSSQL\BACKUP\MyDatabase_20141212.bak' WITH NOFORMAT , NOINIT , NAME = N'MyDatabase_20141212' , SKIP , REWIND , NOUNLOAD , STATS = 10 """ conn.cursor.execute(SQL_command) conn.cursor.commit() The above code give me an error message: pyodbc.ProgrammingError: ('42000', '[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot perform a backup or restore operation

SqlAlchemy equivalent of pyodbc connect string using FreeTDS

房东的猫 提交于 2019-11-28 04:32:48
The following works: import pyodbc pyodbc.connect('DRIVER={FreeTDS};Server=my.db.server;Database=mydb;UID=myuser;PWD=mypwd;TDS_Version=8.0;Port=1433;') The following fails: import sqlalchemy sqlalchemy.create_engine("mssql://myuser:mypwd@my.db.server:1433/mydb?driver=FreeTDS& odbc_options='TDS_Version=8.0'").connect() The error message for above is: DBAPIError: (Error) ('08001', '[08001] [unixODBC][FreeTDS][SQL Server]Unable to connect to data source (0) (SQLDriverConnectW)') None None Can someone please point me in the right direction? Is there a way I can simply tell sqlalchemy to pass a

How to see the real SQL query in Python cursor.execute using pyodbc and MS-Access

旧时模样 提交于 2019-11-28 04:29:33
I use the following code in Python (with pyodbc for a MS-Access base). cursor.execute("select a from tbl where b=? and c=?", (x, y)) It's Ok but, for maintenance purposes, I need to know the complete and exact SQL string send to the database. Is it possible and how ? It differs by driver. Here are two examples: import MySQLdb mc = MySQLdb.connect() r = mc.cursor() r.execute('select %s, %s', ("foo", 2)) r._executed "select 'foo', 2" import psycopg2 pc = psycopg2.connect() r = pc.cursor() r.execute('select %s, %s', ('foo', 2)) r.query "select E'foo', 2" joseph You can use print cursor._last

Retrieving Data from SQL Using pyodbc

[亡魂溺海] 提交于 2019-11-28 04:21:45
I am trying to retrieve data from an SQL server using pyodbc and print it in a table using Python. However, I can only seem to retrieve the column name and the data type and stuff like that, not the actual data values in each row of the column. Basically I am trying to replicate an Excel sheet that retrieves server data and displays it in a table. I am not having any trouble connecting to the server, just that I can't seem to find the actual data that goes into the table. Here is an example of my code: import pyodbc cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=SQLSRV01;DATABASE=DATABASE

In Python, Using pyodbc, How Do You Perform Transactions?

流过昼夜 提交于 2019-11-28 03:57:26
问题 I have a username which I must change in numerous (up to ~25) tables. (Yeah, I know.) An atomic transaction seems to be the way to go for this sort of thing. However, I do not know how to do this with pyodbc. I've seen various tutorials on atomic transactions before, but have never used them. The setup: Windows platform, Python 2.6, pyodbc, Microsoft SQL 2005. I've used pyodbc for single SQL statements, but no compound statements or transactions. Best practices for SQL seem to suggest that

Access second result set of stored procedure with SQL or other work-around? Python\pyodbc

拈花ヽ惹草 提交于 2019-11-28 03:20:13
问题 I'm using python\pyodbc and would like to access the second result set of a stored procedure. As near as I can tell, pyodbc does not support multiple result sets. Additionally, I can't modify the stored procedure. Are there any options to access the second result set using SQL or some other work-around? Perhaps create a second stored procedure that only returns the second result set of the first? 回答1: No need for anything fancy. Just use nextset: import pyodbc db = pyodbc.connect ("") q = db