pyodbc

Pyodbc giving exception with older version of sql driver but failing with latest version

浪子不回头ぞ 提交于 2021-01-29 09:26:08
问题 I am trying to connect a SQL server using pyodbc. In that server SSL3.0 is disabled and TLS 1.1 and 1.2 is enabled. When I am using the oldest driver {SQL Server}. I am getting the below exception handled. pyodbc.connect('DRIVER={SQL Server};SERVER=XX;DATABASE=XX;UID=XX;PWD=XX;' ('08001', '[08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]SSL Security error (18) (SQLDriverConnect); [08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (SECDoClientHandshake()). (772)') However

How to parameterize datestamp in pyODBC query?

…衆ロ難τιáo~ 提交于 2021-01-28 09:03:15
问题 I'm using pyodbc together with QODBC to construct an ODBC query. I'm having trouble inserting datestamp parameters. Here you can see the escalation starting from the literal version (1) to string-format version (2) to error-state versions. ( Note DateFrom & DateTo ): sql = "sp_report ProfitAndLossStandard show Amount_Title, Text, Label, Amount parameters DateFrom = {d'2018-02-12'}, DateTo = {d'2018-02-18'}, SummarizeColumnsBy='TotalOnly', ReturnRows='All'" sql = "sp_report

Improve pandas' to_sql() performance with SQL Server

拈花ヽ惹草 提交于 2021-01-28 06:31:22
问题 I come to you because i cannot fix an issues with pandas.DataFrame.to_sql() method. I've made the connection between my script and my database, i can send queries, but actually it's too slow for me. I would like to find a way to improve the performance of my script on this. Maybe someone will find a solution? Here is my code : engine = sqlalchemy.create_engine(con['sql']['connexion_string']) conn = engine.connect() metadata = sqlalchemy.Metadata() try : if(con['sql']['strategy'] == 'NEW'):

import data from excel to postgres in python using pyodbc

浪尽此生 提交于 2021-01-27 20:33:35
问题 I am importing data from MS-Excel to PostgreSQL in python(2.6) using pyodbc . The problem faced is: There are characters like left single quotation mark(ANSI hex code : 0x91) , etc in the excel source. Now, when it is import into PostgreSQL using pyodbc, it terminates and gives the error DatabaseError: invalid byte sequence for encoding "UTF8": 0x91 . What I tried: I used decode('unicode_escape') for the time being. But, this cannot be done as this simply removes/escapes the concerned

Python : How to switch from one database to another depending upon filedate in the query through 'pyodbc.connect' or something?

混江龙づ霸主 提交于 2021-01-20 12:32:09
问题 value_date = (pd.to_datetime('30-Oct-2019').strftime('%d-%b-%Y')).upper() iss_cnxn = pyodbc.connect('driver={SQL Server Native Client 11.0};' 'server=abc;' 'database=xyz;' 'trusted_connection=yes') sql_query = ' '.join(f"""select xxx as x, yyy as y, zzz as z, from dbo.abcd P WITH(NOLOCK) where filedate = '{value_date}'""".split()) What is the best way to determine the database based on the ‘filedate’ that we are querying? In the example I have hardcoded the value_date as 30th Oct 2019 but we

Python/ SQL : replacing the empty strings of a DataFrame by a “Null” value to insert the data in a database

家住魔仙堡 提交于 2021-01-20 08:48:02
问题 Let's say that I have this dataframe : REFERENCE = ["GZF882348G", "SFGUZBJLNJU", "FTLNGZ242112", "DFBHGVGHG543"] IBAN = ["FR7343563", "FR4832545", "FR9858331", "FR2001045"] DEBIT = [26, '', 856, ''] CREDIT = ['', 324, '', 876] MONTANT = [641, 33, '', 968] df = pd.DataFrame({'Référence' : REFERENCE, 'IBAN' : IBAN, 'Débit' : DEBIT, 'Crédit' : CREDIT, 'Montant' : MONTANT}) I have a problem of format to insert this kind of data in my database. The columns "Débit", "Crédit", "Montant" are defined

Python连接Access数据库

送分小仙女□ 提交于 2021-01-10 08:52:12
前言 今天想要用Python访问Access数据库,折腾了半天,特记录一下 背景 最近想将一些文件记录下来,存入数据库,为此拿LabVIEW写了一个版本,记录环境配置为: LabVIWE:2015 Access:2016 驱动连接字符串: Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;Jet OLEDB:Database Password=;Persist Security Info=False 虽然用LabVIEW已经实现功能,但觉得还是太笨重了,所以打算用Python再实现一遍。 数据库连接 数据库连接网上大致有两种方法,一种是使用 pyodbc ,另一种是使用 win32com.client ,测试了很多遍,最终只有pyodbc成功,而且比较好用,所以这里只介绍这种方法 环境安装 由于LabVIEW已经完成实现,所以环境主要是Python 2.7 和 Access 2016 为了加载需要的库,python 2.7 安装了Pip工具 工具库安装 在此基础上安装pyodbc工具库,在cmd窗口执行如下语句安装 pip install pyodbc 程序实现 import pyodbc DBfile = r"test.mdb" # 数据库文件 conn = pyodbc.connect(r"Driver={Driver do

Python and SQL : replacing the empty strings of a DataFrame by a “Null” value of SQL to insert the data in a database without error of format [duplicate]

雨燕双飞 提交于 2021-01-07 02:40:52
问题 This question already has answers here : Python/ SQL : replacing the empty strings of a DataFrame by a “Null” value to insert the data in a database (4 answers) Python Pandas write to sql with NaN values (2 answers) Replacing Pandas or Numpy Nan with a None to use with MysqlDB (7 answers) Closed last month . Let's say that I have this dataframe and this code to insert my data in the data base : import pandas as pd import pyodbc REFERENCE = ["GZF882348G", "SFGUZBJLNJU", "FTLNGZ242112",

Airflow Scheduler with SQL Server backend and pyodbc

安稳与你 提交于 2021-01-04 05:26:05
问题 I have setup Airflow a SQL Server as backend (SQL Azure). Init DB is successful. I am trying to run a simple dag every 2 minutes. The dag has 2 tasks: print date sleep When it start the airflow scheduler, it creates tasks instances for both the tasks, the first one succeeds & the second one seems to be stuck in "running" state. Looking at scheduler logs, I see the following error repeatedly. [2019-01-04 11:38:48,253] {jobs.py:397} ERROR - Got an exception! Propagating... Traceback (most

Airflow Scheduler with SQL Server backend and pyodbc

大憨熊 提交于 2021-01-04 05:25:25
问题 I have setup Airflow a SQL Server as backend (SQL Azure). Init DB is successful. I am trying to run a simple dag every 2 minutes. The dag has 2 tasks: print date sleep When it start the airflow scheduler, it creates tasks instances for both the tasks, the first one succeeds & the second one seems to be stuck in "running" state. Looking at scheduler logs, I see the following error repeatedly. [2019-01-04 11:38:48,253] {jobs.py:397} ERROR - Got an exception! Propagating... Traceback (most