pyodbc

Python inserts a colon in a Decimal number from Access via pyodbc

人走茶凉 提交于 2019-11-27 07:54:54
问题 I'm having the same problem as this guy and possibly this guy, but I am around to share some code and respond to questions! I have some code in a batch job that reads fields from a Microsoft Access database via pyodbc and prepares the output for display. Here is a snippet. Note the assert. def format_currency(amount): if amount is None: return "" else: result = "$%.2f" % amount assert ":" not in result, ( "That's weird. The value %r of class %s is represented as %s" % (amount, amount.__class_

“CREATE … statement not allowed within multi-statement transaction” when using pyodbc

最后都变了- 提交于 2019-11-27 06:58:06
问题 I'm trying to create a SQL Server database using pyodbc. import pyodbc server = 'AMR112\NAMED1' database = 'msdb' username = '' password = 'mypassword' abcd='yes' ghi='False' #driver = '{/usr/local/lib/libtdsodbc.so}' #for linux of windows driver= '{ODBC Driver 13 for SQL Server}' cnxn = pyodbc.connect('DRIVER='+driver+';PORT=1433;SERVER='+server+??';PORT=1443;DATABASE??='+database+';UID='+??username+';PWD='+ password+';trusted_connection='+ abcd+'; autocommit='+ ghi) cursor = cnxn.cursor()

Error 28000: Login failed for user DOMAIN\\user with pyodbc

∥☆過路亽.° 提交于 2019-11-27 06:41:17
问题 I am trying to use Python to connect to a SQL database by using Window authentication. I looked at some of the posts here (e.g., here), but the suggested methods didn't seem to work. For example, I used the following code: cnxn = pyodbc.connect(driver='{SQL Server Native Client 11.0}', server='SERVERNAME', database='DATABASENAME', trusted_connection='yes') But I got the following error: Error: ('28000', "[28000] [Microsoft][SQL Server Native Client 11.0][SQL Server] Login failed for user

return column names from pyodbc execute() statement

☆樱花仙子☆ 提交于 2019-11-27 05:32:47
问题 from pandas import DataFrame import pyodbc cnxn = pyodbc.connect(databasez) cursor.execute("""SELECT ID, NAME AS Nickname, ADDRESS AS Residence FROM tablez""") DF = DataFrame(cursor.fetchall()) This is fine to populate my pandas DataFrame. But how do I get DF.columns = ['ID', 'Nickname', 'Residence'] straight from cursor ? Is that information stored in cursor at all? 回答1: You can get the columns from the cursor description: columns = [column[0] for column in cursor.description] 回答2: Recent

Retrieving Data from SQL Using pyodbc

可紊 提交于 2019-11-27 05:18:57
问题 I am trying to retrieve data from an SQL server using pyodbc and print it in a table using Python. However, I can only seem to retrieve the column name and the data type and stuff like that, not the actual data values in each row of the column. Basically I am trying to replicate an Excel sheet that retrieves server data and displays it in a table. I am not having any trouble connecting to the server, just that I can't seem to find the actual data that goes into the table. Here is an example

pyodbc - How to perform a select statement using a variable for a parameter

孤者浪人 提交于 2019-11-27 04:52:11
I'm trying to iterate through all the rows in a table named Throughput, but for a specific DeviceName (which I have stored in data['DeviceName']. I've tried the following, but it doesn't work: for row in cursor.execute("select * from Throughput where DeviceName=%s"), %(data['DeviceName']): EDIT: also tried this but it doesn't work: for row in cursor.execute("select * from Throughput where(DeviceName), values(?)", (data['DeviceName']) ): EDIT2: A snippet of my final working code: query = "select * from Throughput where DeviceName = '%s'" % data['Device Name'] try: for row in cursor.execute

SQL IN operator using pyodbc and SQL Server

﹥>﹥吖頭↗ 提交于 2019-11-27 02:21:18
问题 I'm using pyodbc to query to an SQL Server database import datetime import pyodbc conn = pyodbc.connect("Driver={SQL Server};Server='dbserver',Database='db', TrustedConnection=Yes") cursor = conn.cursor() ratings = ("PG-13", "PG", "G") st_dt = datetime(2010, 1, 1) end_dt = datetime(2010, 12, 31) cursor.execute("""Select title, director, producer From movies Where rating In ? And release_dt Between ? And ?""", ratings, str(st_dt), str(end_dt)) but am receiving the error below. Does the tuple

Having Troubles with UnixODBC, FreeTDS, and PyODBC

送分小仙女□ 提交于 2019-11-27 02:18:58
问题 I am having great difficulty getting all three of these to work together in harmony. I guess I'll list all the various configurations, along with the test code to see if a pair of fresh eyes can realize my stupidity. I'm running 12.04 Ubuntu Server and I'm trying to connect to a MSSQL Server 2008 and end up using it with PyODBC. However, when just putting in tsql -S T2 -U Foo -P Bar I get the 1> 2> 3> 4> 5> 6> 7> 8> 9> 10> 11> and etc. Anyway, if anyone would be able to help (and I would be

sql.h not found when installing PyODBC on Heroku

我的梦境 提交于 2019-11-27 01:34:17
问题 I'm trying to install PyODBC on Heroku, but I get fatal error: sql.h: No such file or directory in the logs when pip runs. How do I fix this error? 回答1: To follow up on the answer below... Example for Ubuntu: sudo apt-get install unixodbc unixodbc-dev Example for CentOS: sudo yum install unixODBC-devel On Windows: conn = pyodbc.connect('DRIVER={SQL Server};SERVER=yourserver.yourcompany.com;DATABASE=yourdb;UID=user;PWD=password') On Linux: conn = pyodbc.connect('DRIVER={FreeTDS};SERVER

Pyodbc - “Data source name not found, and no default driver specified”

混江龙づ霸主 提交于 2019-11-27 00:55:59
I have trouble getting pyodbc work. I have unixodbc , unixodbc-dev , odbc-postgresql , pyodbc packages installed on my Linux Mint 14. I am losing hope to find solution on my own, any help appreciated. See details below: Running: >>> import pyodbc >>> conn = pyodbc.connect("DRIVER={PostgreSQL};SERVER=localhost;DATABASE=test;USER=openerp;OPTION=3;") Gives me: >>> pyodbc.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnect)') # odbcinst -j gives : unixODBC 2.2.14 DRIVERS............: /etc/odbcinst.ini SYSTEM DATA