pyodbc

Connecting to MS SQL Server with Windows Authentication using Python?

两盒软妹~` 提交于 2019-12-17 10:23:31
问题 How do I connect MS SQL Server using Windows Authentication, with the pyodbc library? I can connect via MS Access and SQL Server Management Studio, but cannot get a working connection ODBC string for Python. Here's what I've tried (also without 'Trusted_Connection=yes' ): pyodbc.connect('Trusted_Connection=yes', driver='{SQL Server}', server='[system_name]', database='[databasename]') pyodbc.connect('Trusted_Connection=yes', uid='me', driver='{SQL Server}', server='localhost', database='

Speeding up pandas.DataFrame.to_sql with fast_executemany of pyODBC

孤人 提交于 2019-12-17 02:41:48
问题 I would like to send a large pandas.DataFrame to a remote server running MS SQL. The way I do it now is by converting a data_frame object to a list of tuples and then send it away with pyODBC's executemany() function. It goes something like this: import pyodbc as pdb list_of_tuples = convert_df(data_frame) connection = pdb.connect(cnxn_str) cursor = connection.cursor() cursor.fast_executemany = True cursor.executemany(sql_statement, list_of_tuples) connection.commit() cursor.close()

Configure AWS Redshift on Ubuntu 18.04 and use it with pyodbc

佐手、 提交于 2019-12-13 21:23:09
问题 When I try to connect to my DSN using pyodbc I am getting following error: python3: Relink /lib/x86_64-linux-gnu/libudev.so.1' with /lib/x86_64-linux-gnu/librt.so.1' for IFUNC symbol `clock_gettime' Segmentation fault (core dumped) I have tried different solution like reinstalling libudev1 etc. but nothing is working. I tried to connect to using 16.04 VM and I am getting could not connect to server: Connection timed out Is the server running on host xxxxxx and accepting TCP/IP connections on

Unable to CREATE DATABASE via PyODBC connection

僤鯓⒐⒋嵵緔 提交于 2019-12-13 18:28:45
问题 I am using pyodbc in python 2.7 with MS SQL Server 2008R . Here is my code for creating a database (the SQL code which works fine in SQL alone, but crash when executed in python) SQL_command = """ IF EXISTS(SELECT * FROM sys.databases WHERE [name] = 'NewDatabase') DROP DATABASE NewDatabase """ conn.cursor.execute(SQL_command) SQL_command = """ CREATE DATABASE NewDatabase ON ( NAME = 'NewDatabase_data' , FILENAME='D:\MSSQL\DATA\NewDatabase_data.mdf' , SIZE = 4096KB , FILEGROWTH = 4096KB ) LOG

Manage pyodbc memory usage

☆樱花仙子☆ 提交于 2019-12-13 17:31:04
问题 I am using pyodbc (3.0.7) to retrieve data from a SQL Server database. My OS is windows 7 and python is 2.7.7 64 bit. I am running into memory usage issues and I was wondering if there are any solutions. Each time I run my program, the memory usage of the sqlservr.exe process keeps increasing (based on running Tasklist at the command prompt). Here's my code. 1.Connect to database import pyodbc cnxnstring ="DRIVER={SQL Server};Server=servername;Database=dbname; \ User Id=uid; Password=pwd;"

SQL query fails when using pyodbc, but works in SQL

让人想犯罪 __ 提交于 2019-12-13 16:19:21
问题 I am having some trouble with what should be a very simple script. I am just trying to create a new SQL Server database using the Python pyodbc module. The "sqlcommand" parameter I am attempting to pass in works perfectly when I execute it in SQL Server 2012, but it is failing from this python script. Not sure what is going wrong, anyone have any ideas? import pyodbc, os def create_db(folder, db_name): unc = r'\\arcsql\SDE\{0}'.format(folder) if not os.path.exists(unc): os.makedirs(unc) full

Unable to create a second dataframe python pandas

十年热恋 提交于 2019-12-13 15:34:18
问题 My second data frame is not loading values when i create it. Any help with why it is not working? When i make my cursor a list, it has a bunch of values in it, but for whatever reason when i try to do a normal data frame load with pandas a second time, it does not work. My code: conn = pyodbc.connect(constr, autocommit=True) cursor = conn.cursor() secondCheckList = [] checkCount = 0 maxValue = 0 strsql = "SELECT * FROM CRMCSVFILE" cursor = cursor.execute(strsql) cols = [] SQLupdateNewIdField

pyodbc.DataError: ('22018',"[22018] [Microsoft][ODBC SQL Server Driver][SQL Server]Conversion failed ] error

烈酒焚心 提交于 2019-12-13 14:22:25
问题 I have written the following snippet to import a CSV file into an MS SQL Server database but it gives me an error. It is based on code written for Sqlite for Python and changed for MSSQL. import csv, pyodbc import logging def _get_col_datatypes(fin): dr = csv.DictReader(fin) # comma is default delimiter fieldTypes = {} for entry in dr: feildslLeft = [f for f in dr.fieldnames if f not in fieldTypes.keys()] if not feildslLeft: break # We're done for field in feildslLeft: data = entry[field] #

pypyodbc: [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionWrite (send())

白昼怎懂夜的黑 提交于 2019-12-13 07:13:11
问题 My python script reads through around half of the dataset (around 5000 rows out of 10000) and all of a sudden produces this error midway: [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionWrite (send()) I'm using pypyodbc to connect to the Azure SQL server. I haven't been able to find the solution anywhere online. I don't even know whats the cause that's leading to this error. Please help. 回答1: Hope you are doing well. Have you had a chance to look at pyodbc and pymssql? They have a

facing Too few parameters. Expected 1. (-3010) (SQLExecDirectW)')" error in python program

一个人想着一个人 提交于 2019-12-13 06:47:52
问题 using python "pyodbc" module for extarcting data from excel sheet. When I use numeric instead of win_b64, This program works, for string i.e. win_b64 It is showing below error. I want to retrive data like in below condition "where platform = win_b64 and context_id = 806" import pyodbc exFile = r'C:\Python34\abc.xls'conn1 = pyodbc.connect('DRIVER={MicrosoftExcel Driver (*.xls)};DBQ='+exFile,autocommit=True) curs1 = conn1.cursor() excel = curs1.execute('select [problem_name] from [Sheet1$]