pyodbc

How to open a SQL Server .mdf file with Python (pandas)

泄露秘密 提交于 2019-12-02 06:35:07
I'm trying to open a mdf sql database file that I have saved to my desktop. How do you open it as a pandas dataframe? so far all I have is the following: conn=pyodbc.connect(driver='{SQL Server}', dsn=filepath) Its giving me the error message OperationalError: ('08001', '[08001] [Microsoft][ODBC SQL Server Driver]Neither DSN nor SERVER keyword supplied (0) (SQLDriverConnect)') I found another question that was similar but it was also unanswered. I have also been unable to find a good tutorial to start using sql databases with python I'm very new to the topic. Let me know if there is any extra

Connect to MS Access in Python

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 05:47:01
I tried a lot of examples from internet to include a MS Access connection to my python project without sucess I have my python project in Eclipse with Anaconda, and my code is: import win32com.client import pyodbc def ado(): ''' connect with com dispatch objs ''' conn = win32com.client.Dispatch(r'ADODB.Connection') DSN = ('PROVIDER = Microsoft.Jet.OLEDB.4.0;DATA SOURCE = ' + db + ';') conn.Open(DSN) rs = win32com.client.Dispatch(r'ADODB.Recordset') strsql = "select * from Empresas" rs.Open(strsql, conn, 1, 3) t = rs.GetRows() conn.Close() return t def odbc(): ''' connects with odbc ''' constr

pyodbc - add column to MS Access with default value

烂漫一生 提交于 2019-12-02 05:09:33
I'm trying to add a column to an MS Access database table using pyodbc and Python 3.5. Using the expression self.cursor.execute("ALTER TABLE data ADD COLUMN testColumn TEXT(10)") works fine, but when I try to add a default value (DEFAULT "no"), it throws a Syntax error. I've tried multiple combinations, but no luck. Any help is much appreciated! Cheers Sadly, the Access ODBC driver simply does not support the DEFAULT clause for a column in CREATE/ALTER TABLE statements. The ODBC driver and OLEDB provider for Access have diverged somewhat in their DDL support, so unfortunately we can get

pyodbc is not updating table

拜拜、爱过 提交于 2019-12-02 05:00:44
问题 Basically I'm trying to update Column1_mbgl field data in Table1, all based in MS Access database. The script gets executed without any errors, but when the table is checked no update occurred. I have tried two options as shown in the code without any success. The second option is the SQL code generated directly from MS Access query. Can anybody suggest what I'm missing in the code? #import pypyodbc import pyodbc # MS ACCESS DB CONNECTION pyodbc.lowercase = False conn = pyodbc.connect( r

Python truncate at 255 chars when querying MS SqlServer with FreeTDS

六月ゝ 毕业季﹏ 提交于 2019-12-02 04:12:40
问题 i think i have miss something in a query from python using pyodbc over a FreeTDS on a Debian machine. I can not manage to have more than the first 255 characters. if i try to CAST SQL data as describe here: ODBC query on MS SQL Server returning first 255 characters only in PHP PDO (FreeTDS) with : SELECT CAST(myText as TEXT) FROM mytable i get empty/zero length string, i have also test with no more success to : change size as describe with the config below, i only get first 255 characters

JOINing mdb tables with pyodbc

你。 提交于 2019-12-02 04:02:11
问题 I try to JOIN two MS access tables this way in python (pyodbc): query = "SELECT Karta.id FROM Karta JOIN zaznam ON (Karta.id=zaznam.karta)" cursor.execute(query) But I am getting an error: pyodbc.ProgrammingError 42000 microsoft access driver syntax error in form clause -3506 SqlExecDirectW What am I doing wrong? 回答1: You need to specify the type of join ( INNER , LEFT OUTER , RIGHT OUTER ) in the FROM clause. The type of join used depends on what you want the results to contain, I'm guessing

PYODBC InterfaceError- Data source name not found

▼魔方 西西 提交于 2019-12-02 03:52:46
I am trying to connect Python to MS Access Database using pyodbc but every time I get the following error: pyodbc.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)') And this what I have written to connect python to MS Access: import pyodbc conn = pyodbc.connect(r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=D:\PILOT_DATA.accdb;') cursor = conn.cursor() cursor.execute('select * from p_inventor') for row in cursor.fetchall(): print (row) According to the error, it doesn't find the Data

JOINing mdb tables with pyodbc

烂漫一生 提交于 2019-12-02 01:44:27
I try to JOIN two MS access tables this way in python (pyodbc): query = "SELECT Karta.id FROM Karta JOIN zaznam ON (Karta.id=zaznam.karta)" cursor.execute(query) But I am getting an error: pyodbc.ProgrammingError 42000 microsoft access driver syntax error in form clause -3506 SqlExecDirectW What am I doing wrong? You need to specify the type of join ( INNER , LEFT OUTER , RIGHT OUTER ) in the FROM clause. The type of join used depends on what you want the results to contain, I'm guessing you want an INNER JOIN . A reference for the join types available in Access can be found here . Sample code

Working with dates in Access using pyodbc giving “Too few parameters” error

纵然是瞬间 提交于 2019-12-02 01:39:56
问题 I am using Python with a pyodbc import. I am using Microsoft Office 2013 64bit. I am attempting to query an accdb database to select distinct dates within a range and assign them to a cursor so I can then append them to a list. My Access database has a table named Closing_prices, and a column named Date_, which has the data type "Date/Time". My code is as follows: cursor=conx.cursor() query="select distinct Date_ FROM Closing_prices where Date_ >= '10/8/2011' and Date_ < '30/04/2014'" cursor

pyodbc is not updating table

大城市里の小女人 提交于 2019-12-02 01:24:07
Basically I'm trying to update Column1_mbgl field data in Table1, all based in MS Access database. The script gets executed without any errors, but when the table is checked no update occurred. I have tried two options as shown in the code without any success. The second option is the SQL code generated directly from MS Access query. Can anybody suggest what I'm missing in the code? #import pypyodbc import pyodbc # MS ACCESS DB CONNECTION pyodbc.lowercase = False conn = pyodbc.connect( r"Driver={Microsoft Access Driver (*.mdb, *.accdb)};" + r"Dbq=C:\temp\DB_access.accdb;") # OPEN CURSOR AND