pyodbc

Using an Access database (.mdb) with Python on Ubuntu [duplicate]

纵然是瞬间 提交于 2019-12-05 23:56:07
问题 This question already has answers here : Working with an Access database in Python on non-Windows platform (Linux or Mac) (4 answers) Closed 3 years ago . I'm trying to use pyodbc to access a .mdb on Ubuntu. I've based my progress so far on this link Query crashes MS Access I have installed pyodbc, unixodbc, and unixodbc-dev My code looks like this: import csv import pyodbc MDB = 'URY.mdb' DRV ='Microsoft Access Driver (*.mdb)' PWD = 'pass' conn = pyodbc.connect('DRIVER=%s;DBQ=%s;PWD=%s' %

PyODBC return error, but why?

我的未来我决定 提交于 2019-12-05 20:10:11
I try execute T-SQL query in two cases (i use Win7, python 3.2, MS SQL Server express 2008,pyodbc for python 3.2): -case 1: using MS SQL Server Management Studio i try to execute query: USE master;CREATE DATABASE Sales ON (NAME = Sales_dat,FILENAME = 'C:\saledat.mdf', SIZE = 10, MAXSIZE = 50, FILEGROWTH = 5 ) LOG ON ( NAME = Sales_log, FILENAME = 'C:\salelog.ldf', SIZE = 5MB, MAXSIZE = 25MB, FILEGROWTH = 5MB ); it return successful result -case 2: import pyodbc cxnn=pyodbc.connect('DSN=SERVER;UID=sa;PWD=password') cur=cxnn.cursor() cur.execute("USE master;CREATE DATABASE Sales ON (NAME = Sales

pyodbc, call stored procedure with table variable

别说谁变了你拦得住时间么 提交于 2019-12-05 18:09:26
I have to call a MS SQLServer stored procedure with a table variable parameter. /* Declare a variable that references the type. */ DECLARE @TableVariable AS [AList]; /* Add data to the table variable. */ INSERT INTO @TableVariable (val) VALUES ('value-1'); INSERT INTO @TableVariable (val) VALUES ('value-2'); EXEC [dbo].[sp_MyProc] @param = @TableVariable Works well in the SQL Sv Management studio. I tried the following in python using PyOdbc: cursor.execute("declare @TableVariable AS [AList]") for a in mylist: cursor.execute("INSERT INTO @TableVariable (val) VALUES (?)", a) cursor.execute("

SQL Server DATE retrieved into pandas as a string

萝らか妹 提交于 2019-12-05 16:49:55
When I pull a "Date" variable from SQL Server into Python/Pandas, it comes through as an 'Object'. I have installed and tried several drivers (commented drivers tried shown in the code), each time with the same results: import pandas as pd import pyodbc conn_str = ( r'Driver={SQL Server Native Client 11.0};' # r'Driver={SQL Server Native Client 10.0};' # r'Driver={ODBC Driver 11 for SQL Server};' # r'Driver={ODBC Driver 13 for SQL Server};' # r'Driver={SQL Server};' r'Server=MyServer;' r'Database=MyDB;' r'Trusted_Connection=yes;' ) cnxn = pyodbc.connect(conn_str) sql = ( "Select cast('2017-08

How to get the IDENTITY value when using INSERT … OUTPUT with pyodbc

♀尐吖头ヾ 提交于 2019-12-05 11:55:16
I am trying to get the ID of a newly inserted row by using OUTPUT . However, I encountered the HY010 error. The following query/code is what I use: string = """ SET NOCOUNT ON; DECLARE @NEWID TABLE(ID INT); INSERT INTO dbo.t1 (Username, Age) OUTPUT inserted.id INTO @NEWID(ID) VALUES(?, ?) SELECT ID FROM @NEWID """ cursor.execute(string, "John Doe", 35) cursor.commit() id = cursor.fetchone()[0] the last line id = cursor.fetchone()[0] led to a HY010 error (see below). Any advice would be greatly appreciated! pyodbc.Error: ('HY010', '[HY010] [Microsoft][ODBC SQL Server Driver]Function sequence

How can i pass configuration variable values into the pyodbc connect command?

倖福魔咒の 提交于 2019-12-05 10:58:40
I have a .ini(configuration file) where i have mentioned the server name, Database Name, UserName and Password with which i can connect my app to the MSSQL self.db = pyodbc.connect('driver={SQL Server};server=homeserver;database=testdb;uid=home;pwd=1234') corresponding data mentioned above connect statement is now in config.ini ` self.configwrite = ConfigParser.RawConfigParser() configread = SafeConfigParser() configread.read('config.ini') driver = configread.get('DataBase Settings','Driver') server = str(configread.get('DataBase Settings','Server')) db = str(configread.get('DataBase Settings'

Passing table name as a parameter in pyodbc

纵饮孤独 提交于 2019-12-05 06:32:59
I am trying to pass a table name in pyodbc as a parameter to access data from ms sql 2005. I've tried to substitute it with ? but it never works. I would be glad to receive any advice on how to accomplish this. Since you are using pyodbc, I assume you are not calling a SPROC. I recommend building your SQL string in python and then passing it to SQL to execute. import pyodbc dbconn = pyodbc.connect(ConnectionString) c = dbconn.cursor() j = 'table1' #where table1 is entered, retreived, etc query = "Select * from %s" % j c.execute(query) result = c.fetchall() print 'Done' You can't have variable

SQL Update statement but using pyodbc

你。 提交于 2019-12-05 02:41:29
I am using a pyodbc driver to connect to a microsoft access table using SQL. Does anyone know how I go about replacing fields within this table?? I have though about deleting the row and then putting the row back but that would change the primary key due to the autonumber in access. I have this for inserting into the Progress table: cnxn = pyodbc.connect('Driver={Microsoft Access Driver (*.mdb, *.accdb)}; Dbq=C:\\Users\\...............(file location)') cursor = cnxn.cursor() cursor.execute("insert into Progress(CockpitDrill,Mirrors,MoveOff,TurnLeft) values (?,?,?,?)",cockpit,mirrors,moveOff

connect to Azure SQL database via pyodbc

帅比萌擦擦* 提交于 2019-12-05 01:51:18
问题 I use pyodbc to connect to my local SQL database which works withoout problems. SQLSERVERLOCAL='Driver={SQL Server Native Client 11.0};Server=(localdb)\\v11.0;integrated security = true;DATABASE=eodba;' cnxn = pyodbc.connect(SQLSERVERLOCAL) #works I try the connection to the azure sql database with: SQLSERVERAZURE='Driver={SQL Server Native Client 10.0};Server=tcp:mydatbase.database.windows.net,1433;Database=mydb;Uid=myuser@myerver;Pwd=mypass;Encrypt=yes;Connection Timeout=30;' cnxn = pyodbc

Is it possible to have SQL Server convert collation to UTF-8 / UTF-16

ぃ、小莉子 提交于 2019-12-05 01:10:09
In a project I am working on my data is stored in SQL Server, with the collation Danish_Norwegian_CI_AS . The data is output'ed through FreeTDS and ODBC, to python that handles the data as UTF-8. Some of the characters, like å, ø and æ, are not being coded correctly, causing the project progress to grind to a halt. I spent a couple of hours reading about the confusing world of encodings, collation and code-pages, and feel like I have gotten a better understanding of the entire picture. Some of the articles I have read, makes me think that it would be possible to: Specify in the SQL select