pyodbc

Pass Azure AD Token for Azure SQL DB in pre-connection arguments to SQLAlchemy create_engine()

℡╲_俬逩灬. 提交于 2020-08-26 06:49:38
问题 I'm wanting to connect to an Azure SQL DB via SQLAlchemy with an AD token. I've followed https://github.com/felipefandrade/azuresqlspn and can successfully connect with this method. However, I want to extend this and use SQLAlchemy to manage the connection. from os import environ import struct import adal from sqlalchemy import create_engine import pyodbc clientSecret = environ.get('clientSecret') clientID = environ.get('clientID') tenantID = environ.get('tenantID') authorityHostUrl = "https:

Load CSV to .mdb using pyodbc and pandas

a 夏天 提交于 2020-08-26 04:58:07
问题 Background story: I work on finance (not a developer, so help is very appreciated), my department currently relies heavily on excel and vba to automate as much as possible of our tasks. The company just validated a python distribution and we're now allowed to use it, so I just thought on giving a try. Challenge: My first challenge was to load a CSV file into a MSAcess database (because not all of us are tech savy enough to work purely using dev tools and DBs, so need to make things easy for

Waiting for DB restore to finish using sqlalchemy on SQL Server 2008

六月ゝ 毕业季﹏ 提交于 2020-08-23 07:33:38
问题 I'm trying to automate my db restores during development, using TSQL on SQL Server 2008, using sqlalchemy with pyodbc as a transport. The command I'm executing is: """CREATE DATABASE dbname restore database dbname FROM DISK='C:\Backups\dbname.bak' WITH REPLACE,MOVE 'dbname_data' TO 'C:\Databases\dbname_data.mdf',MOVE 'dbname_log' TO 'C:\Databases\dbname_log.ldf'""" Unfortunately, the in SQL Management Studio, after the code has run, I see that the DB remains in state "Restoring...". If I

Connect to Linked Server via SQL Server pyodbc connection?

半城伤御伤魂 提交于 2020-08-09 12:27:57
问题 I can currently connect to my SQL Server and query any database I want to directly. The problem is when I want to query a linked server. I cannot directly reference the linked servers name in the connect() method and I have to connect to a local database first and then run an OPENQUERY() against the linked server. This seams like a odd work around. Is there a way to query the linked server directly (from my research you cannot connect directly to a linked server) or at least connect to the

Get MSSQL table column names using pyodbc in python

我与影子孤独终老i 提交于 2020-08-07 09:43:28
问题 I am trying to get the mssql table column names using pyodbc, and getting an error saying ProgrammingError: No results. Previous SQL was not a query. Here is my code: class get_Fields: def GET(self,r): web.header('Access-Control-Allow-Origin', '*') web.header('Access-Control-Allow-Credentials', 'true') fields = [] datasetname = web.input().datasetName tablename = web.input().tableName cnxn = pyodbc.connect(connection_string) cursor = cnxn.cursor() query = "USE" + "[" +datasetname+ "]" +

Connect to Azure SQL in Python with MFA Active Directory Interactive Authentication without using Microsoft.IdentityModel.Clients.ActiveDirectory dll

不羁岁月 提交于 2020-08-05 06:18:15
问题 To connect to Azure SQL Database using MFA (which is in SSMS as "Active Directory - Universal") Microsoft recommends and currently only has a tutorial on connecting with C# using Microsoft.IdentityModel.Clients.ActiveDirectory Setting Authentication='Active Directory Interactive'; in a regular ODBC connection string from Python or Powershell results in the error Cannot find an authentication provider for 'ActiveDirectoryInteractive' This seems to be because per Microsoft's example code at

Can't connect to remote SQL Servers outside of network with PYODBC

China☆狼群 提交于 2020-08-02 07:23:17
问题 I for some reason can't seem to connect to any SQL Server that is outside of our network, yet have no problem if I'm within the network via VPN. My code is as such for local connection: sql = pyodbc.connect( 'DRIVER={FreeTDS};' 'SERVER=192.168.1.xx\ROA;' 'DATABASE=RentalDB;' 'UID=xxxxxxx;' 'PWD=xxxxxxx' ) and the following is what I'm trying for remote: sql = pyodbc.connect( 'DRIVER={FreeTDS};' 'SERVER=69.178.xx.xx/ROA;' 'DATABASE=RentalDB;' 'UID=xxxxxxxx;' 'PWD=xxxxxxxx' ) When trying to

Db2 driver for Django?

心不动则不痛 提交于 2020-07-23 06:41:09
问题 It seems to me that Django currenty only provides 4 backend database engine which are: 'django.db.backends.postgresql' 'django.db.backends.mysql' 'django.db.backends.sqlite3' 'django.db.backends.oracle' If I use MySQL, all I have to do is just fill the Engine with 'django.db.backends.mysql' . But now, because my main Database is DB2, I'm having some issues to connect it with pyodbc. What is needed? import os SECRET_KEY = 'o0zdmzzdw44tkd5a7o*h-@*bo)r@f#)!)$)8f-y%=sn*kr)@t%' DEBUG = True

Db2 driver for Django?

流过昼夜 提交于 2020-07-23 06:40:16
问题 It seems to me that Django currenty only provides 4 backend database engine which are: 'django.db.backends.postgresql' 'django.db.backends.mysql' 'django.db.backends.sqlite3' 'django.db.backends.oracle' If I use MySQL, all I have to do is just fill the Engine with 'django.db.backends.mysql' . But now, because my main Database is DB2, I'm having some issues to connect it with pyodbc. What is needed? import os SECRET_KEY = 'o0zdmzzdw44tkd5a7o*h-@*bo)r@f#)!)$)8f-y%=sn*kr)@t%' DEBUG = True