pyodbc

Python - format single quote in SQL statement PyODBC

て烟熏妆下的殇ゞ 提交于 2019-12-12 06:13:45
问题 I already tried a couple of drivers: pymsql, pyobdc and still have issue with format single quote in SQL. Examples of code below: CASE 1. import pyodbc UPDATE_SQL3 = """ UPDATE STATION SET STATION_NAME = ?, STATION_TITLE = ?, ACTIVE = ? WHERE STATION_ID = ? """ conn = pyodbc.connect('DRIVER={SQL Server};SERVER=local;DATABASE=DB;UID=me;PWD=pass') cursor = conn.cursor() cursor.execute(UPDATE_SQL3 % (name, title, active, id )) This code doesn't compile: "not all arguments converted during string

Access database UPSERT with pyodbc

拜拜、爱过 提交于 2019-12-12 04:48:02
问题 I am using pyodbc to update an Access database. I need the functionality of an UPSERT. ON DUPLICATE KEY UPDATE doesn't exist in Access SQL, and REPLACE is not an option since I want to keep other fields. There are a lot of suggestions out there how to solve that, so this is the solution which I put together: for table_name in data_source: table = data_source[table_name] for y in table: if table_name == "whatever": SQL_UPDATE = "UPDATE {} set [Part Name] = '{}', [value] = {}, [code] = {},

cannot connect to 64bit MsAccess database with 64bit Python 3.6.ODBC Driver Error

て烟熏妆下的殇ゞ 提交于 2019-12-12 04:14:25
问题 I have just installed 64-bit microsoft office on a new computer and also installed 64bit python 3.6. I'm trying to connect to an access database with my python script, however I keep getting the following error which suggests I have the 32bit ODBC driver instead of the 64bit driver? Any ideas on how to connect without having to install 32bit MS Office and 32bit Python? This is the error message I get: cnxn = pyodbc.connect(connstr) pyodbc.Error: ('IM002', '[IM002] [Microsoft][ODBC Driver

How to connect to MS Access 97 (with workgroup mdw) database using pyodbc

我是研究僧i 提交于 2019-12-12 03:24:39
问题 In a Python script with pyodbc, I am trying to connect to a still used Access 97 database on our network but I have problems to get the connection (or the connection string) to work. I keep getting the following error: pyodbc.Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnectW)') This is my connection string which fails with above mentioned error: conn = pyodbc.connect('Driver={Microsoft Access Driver (

pyODBC refuses to look for unixODBC, instead looks for iODBC

半世苍凉 提交于 2019-12-12 02:33:47
问题 Is there a way to get pyODBC v3.0.10 to look for the unixODBC driver, instead of the iODBC driver it seems to want to look for? My understanding is that pyODBC v3.0.10 is supposed to do this by default, while versions prior to v3.0.7 required a manual edit to the setup.py file (see reference here). One more clue, I ran this code to list my ODBC sources, and it returned nothing: sources = pyodbc.dataSources() dsns = list(sources.keys()) dsns.sort() sl = [] for dsn in dsns: sl.append('%s [%s]'

pyodbc column name as variable

独自空忆成欢 提交于 2019-12-12 02:29:45
问题 Instead of editing the sql-string when i want to change which column to write to i want to use a variable.. This seems to work. I get no error, but the database is not updated... What is wrong with this? cnxn = pyodbc.connect('DRIVER=FreeTDS;SERVER=dkvmsql08;PORT=1433;DATABASE=dingdong_test;UID=dac\svc-dingdong;PWD=c90346KJHjkhg&%dad742210a3d6fd4436c;T$ cur = cnxn.cursor() name = Dennis cur.execute("UPDATE dbo.timestamp set cur.execute("UPDATE dbo.test set ?=1 where id=?",name, row.id) 回答1:

Unable to connect to database : Pyodbc

旧街凉风 提交于 2019-12-11 18:57:38
问题 I'm trying to connect to an MSSQL database from python on Linux . Whenever I try to connect to database through python . I get the following error : >>> import pyodbc >>> connection=pyodbc.connect('DRIVER={FreeTDS};SERVER=xx.xx.xxx.xxx;DATABASE=xxxxxxxxx;UID=xxxxx;PWD=xxxxxxx;') Traceback (most recent call last): File "<stdin>", line 1, in <module> pyodbc.Error: ('08001', '[08001] [unixODBC][FreeTDS][SQL Server]Unable to connect to data source (0) (SQLDriverConnect)') This is the output for

Python-Oracle connection issue with Pyodbc

爷,独闯天下 提交于 2019-12-11 18:56:32
问题 Tried to connect to the Oracle database using Pyodbc: try: db_connection = pyodbc.connect('DSN=OraDev; PWD=%s' % Key.dbKeys['password']) except pyodbc.Error, err: print >> debug_file, "Database connection failed: %s" %err sys.exit() and it keeps giving me this error message: '[IM014] [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application (0) (SQLDriverConnect) So I am wondering if the culprit is that I am not having the

Connect to MS SQL on a network with SQL Alchemy in Python using Windows Authentication

*爱你&永不变心* 提交于 2019-12-11 18:09:43
问题 I am trying to use pandas.read_sql_table to get data from MS SQL Server (the server is on a network). I use Windows authentication to access the server. Pandas read_sql_table takes a SQL Alchemy connection as an argument for “connection.” I am having a difficult time finding an example that combines: SQL Alchemy MS SQL Server DSN (the “preferred” specification according to SQL Alchemy) Windows authentication I’ve consulted SQL Alchemy, which shows an example using SQL authentication, but not

Python database insert

南笙酒味 提交于 2019-12-11 17:59:42
问题 I've been trying to parse a text file (opened with parameter encoding='utf8') and insert extracted values into an mdb database using pyodbc module. I have tried the code below: for line in fp: tokens = line.split('\t') tokens[4] = tokens[4][:len(tokens[4])-1] #to avoid the \n tokens[1] = tokens[1][1:] #to remove the 'u' from the beginning of utf8 characters like u'\u0622' content = conn.execute("INSERT INTO Entries (PForm, WForm, Code, Freq, Pattern) VALUES ("+tokens[0]+","+tokens[1]+","