pyodbc

PyODBC, cursor.execute() won't insert parameters into SQL String

对着背影说爱祢 提交于 2019-12-02 19:15:01
问题 I am using pypyodbc to insert data into a database and when I use the cursor.execute() command I try to put the sql string and the parameters, but I get the following error: SELECT uid FROM HP_DATA WHERE( hpName = ? AND processID = ? AND ipAddress = ? AND port = ? AND usernameTried = ? AND passwordTried = ? AND fileID = ?); INSERT INTO HP_DATA_LOGIN_DETAIL(uid, attackDate, gmtOffset) VALUES(?, CONVERT(DATETIME, ?, 126), ?); 2016-04-19T05:40:58.000 ('22007', '[22007] [Microsoft][ODBC SQL

What should be my configuration to load pyodbc module on Apache Server to run simple queries mssql server database

China☆狼群 提交于 2019-12-02 16:31:41
问题 As I'm new to python. I need to know simple database connectivity with Apache HTTP Server. Just I need to run the below code in Apache HTTP Server. import pyodbc cnxn = pyodbc.connect("Driver={ODBC Driver 13 for SQL Server};" "Server=DESKTOP-C6;" "Database=demo2017;" "Trusted_Connection=yes;") cursor = cnxn.cursor() cursor.execute('SELECT * FROM person') for row in cursor: print('row = %r' % (row,)) cursor.close(); cnxn.close(); I have tried to run in python shell. It executed successfully.

ValueError with Pandas - shaped of passed values

时光怂恿深爱的人放手 提交于 2019-12-02 16:11:23
问题 I'm trying to use Pandas and PyODBC to pull from a SQL Server View and dump the contents to an excel file. However, I'm getting the error when dumping the data frame (I can print the colums and dataframe content): ValueError: Shape of passed values is (1, 228), indices imply (2, 228) There are several other issues on this forum pertaining to the same issue, but none discuss pulling from a SQL Server table. I can't figure out what is causing this error, and altering the view to cast the source

PYODBC InterfaceError- Data source name not found

假如想象 提交于 2019-12-02 13:38:25
问题 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

pyodbc - add column to MS Access with default value

断了今生、忘了曾经 提交于 2019-12-02 12:09:48
问题 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 回答1: Sadly, the Access ODBC driver simply does not support the DEFAULT clause for a column in CREATE/ALTER TABLE statements. The ODBC driver

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

岁酱吖の 提交于 2019-12-02 11:26:09
问题 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

Pyodbc: Issue inserting into MS Access database

可紊 提交于 2019-12-02 10:15:39
I'm trying to automate data collection from the results of an online form, compile them into an Excel file, and then upload the data from the Excel file into Access. I have a Python script that does this for another database and works perfectly fine, but the same code does not work for the new database for some reason. Using pydobc, I'm able to successfully connect to the database and perform simple SELECT and INSERT statements such as: DBcursor.execute("insert into Table1(Field1, Field2) values(?, ?)", ('Test 3', 'Test 4')) This is properly inserted into the database and throws no exception.

PyODBC, cursor.execute() won't insert parameters into SQL String

时光毁灭记忆、已成空白 提交于 2019-12-02 10:04:30
I am using pypyodbc to insert data into a database and when I use the cursor.execute() command I try to put the sql string and the parameters, but I get the following error: SELECT uid FROM HP_DATA WHERE( hpName = ? AND processID = ? AND ipAddress = ? AND port = ? AND usernameTried = ? AND passwordTried = ? AND fileID = ?); INSERT INTO HP_DATA_LOGIN_DETAIL(uid, attackDate, gmtOffset) VALUES(?, CONVERT(DATETIME, ?, 126), ?); 2016-04-19T05:40:58.000 ('22007', '[22007] [Microsoft][ODBC SQL Server Driver][SQL Server]Conversion failed when converting date and/or time from character string.') This

Parametrizing TOP value in tsql and pyodbc

风格不统一 提交于 2019-12-02 08:56:59
问题 I try to parametrize number of top rows to get from table. I tried it with db.cursor.execute( ''' SELECT TOP ? VALUE FROM mytable WHERE param = ? ''', top_value, param ) and it showed pyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near '@P1'. (102) (SQLExecDirectW)") with string interpolation like bellow it works. db.cursor.execute( f''' SELECT TOP {top_limit} VALUE FROM mytable WHERE SITE_SK_FK = ? ''', param ) Do I need to

What should be my configuration to load pyodbc module on Apache Server to run simple queries mssql server database

我们两清 提交于 2019-12-02 07:47:39
As I'm new to python. I need to know simple database connectivity with Apache HTTP Server. Just I need to run the below code in Apache HTTP Server. import pyodbc cnxn = pyodbc.connect("Driver={ODBC Driver 13 for SQL Server};" "Server=DESKTOP-C6;" "Database=demo2017;" "Trusted_Connection=yes;") cursor = cnxn.cursor() cursor.execute('SELECT * FROM person') for row in cursor: print('row = %r' % (row,)) cursor.close(); cnxn.close(); I have tried to run in python shell. It executed successfully. But with Apache HTTP Server results in 500 Internal Server Error . Also in httpd.conf file: LoadModule