pyodbc

How to connect to MS-SQL server without database name using pyodbc python?

How to connect to MS-SQL server without database name using pyodbc python? Question: I need to connect to the ms-sql database and then create a new database there using python script. I have the user credentials for the login. So how to create the connection to the ms-sql server using python. Asked By: Arun Yadav …

Total answers: 2

Parameter error for pyodbc insert/apppend

Parameter error for pyodbc insert/apppend Question: I am trying to insert/append into access a dataframe using pyodbc. However; when I run the code, I get an error: ProgrammingError: (‘The SQL contains 21 parameter markers, but 1 parameter were supplied’, ‘HY000’) my sample code is: for row in tDjango: cursor.execute( ‘INSERT INTO TDjango (Eid, Eventtype, Location, …

Total answers: 1

Python/Pyodbc/SQL – Updating a table and setting a field to a CSV File

Python/Pyodbc/SQL – Updating a table and setting a field to a CSV File Question: I am trying to use pyodbc to update an existing MS Access database table with a very long multiline string. The string is actually a csv that has been turned into a string. The query I am trying to use to …

Total answers: 2

pd.DataFrame.to_sql() is prepending the server name and username to the table name

pd.DataFrame.to_sql() is prepending the server name and username to the table name Question: I have a Pandas dataframe df which I want to push to a relational database as a table. I setup a connection object (<Connection>) using SQLAlchemy (pyodbc is the connection engine), and called the command df.to_sql(<Table_Name>, <Connection>) which I was able to …

Total answers: 1

sqlalchemy + pyodbc how to trust certificate?

sqlalchemy + pyodbc how to trust certificate? Question: I have a python script using pyodbc that connects to a remote server with sql server running on it. I have a package I wrote with functions using sqlalchemy that I was able to use on one of my computers. I connected with this string: driver = …

Total answers: 2

Execute Stored Procedure with Parameters in python

Execute Stored Procedure with Parameters in python Question: I am trying to execute a stored procedure but it is getting complicated, my code in python is: import pyodbc as pyodbc import pandas as pd server = ‘server’ bd = ‘bd’ usuario = ‘usuario’ contrasena = ‘contrasena’ try: conexion = pyodbc.connect(‘DRIVER={ODBC DRIVER 17 for SQL Server};SERVER=’+server+’;DATABASE=’+bd+’;UID=’+usuario+’;PWD=’+contrasena, …

Total answers: 1

Can python cursor.execute accept multiple queries in one go?

Can python cursor.execute accept multiple queries in one go? Question: Can the cursor.execute call below execute multiple SQL queries in one go? cursor.execute("use testdb;CREATE USER MyLogin") I don’t have python setup yet but want to know if above form is supported by cursor.execute? import pyodbc # Some other example server values are # server = …

Total answers: 4

Creating AWS Lambda function using python pyodbc library throw an error "module 'pyodbc' has no attribute ' connect'

Creating AWS Lambda function using python pyodbc library throw an error "module 'pyodbc' has no attribute ' connect' Question: I am trying to create a simple Lambda function to query the msdb of AWS RDS SQL server to monitor for failed jobs. I downloaded the python module pyodbc from https://github.com/Miserlou/lambda-packages/tree/master/lambda_packages/pyodbc changed the file type from …

Total answers: 2

Cannot install pyodbc, missing header files, command prompt: fatal error C1083: Cannot open include file: 'windows.h': No such file or directory

Cannot install pyodbc, missing header files, command prompt: fatal error C1083: Cannot open include file: 'windows.h': No such file or directory Question: I’m trying to install pyodbc for python 3.9.2 (32-bit), however I keep getting the error: C:UsersICAPP02AppDataLocalTemppip-install-0c78okb8pyodbc_d782ffa5512448c49f83e214e7ec4434srcpyodbc.h(19): fatal error C1083: Cannot open include file: ‘windows.h’: No such file or directory error: command ‘C:Program Files …

Total answers: 2