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

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.

Hope you are doing well. Have you had a chance to look at pyodbc and pymssql?
They have a better community presence and are actively maintained. If the script fails with these drivers as well, there might be an issue with your script. I can try to help you troubleshoot if you share it.
Let me know if the issue gets fixed with the other drivers and if it does not I can help you out.
Thanks,
Meet Bhagdev
Program Manager, Microsoft

I tried to reproduce the issue, but failed. And I observed that the package last updated in 2013. It's an old and no longer maintenance package for Python ODBC. So I don't recommend to continue to use it to access the latest Azure SQL Database.
I strongly recommended you to use the package pymssql. It's the Azure offical recommend odbc driver for Python, please refer to https://azure.microsoft.com/en-us/documentation/articles/sql-database-libraries/.
It can very good support any OS environment contains Windows, Linux, MacOS. You can refer to these docs https://azure.microsoft.com/en-us/documentation/articles/sql-database-develop-python-simple-windows/, https://azure.microsoft.com/en-us/documentation/articles/sql-database-develop-python-simple-ubuntu-linux/ and https://azure.microsoft.com/en-us/documentation/articles/sql-database-develop-python-simple-mac-osx/ to getting started.
If you want to dive into the package usgae, please refer to the offical document http://pymssql.org/en/latest/index.html.
Best Regards.

Related

Trouble connecting python to cx_oracle - error ORA-01804 [duplicate]

I am having an issue to connect my C++ application to my Oracle DB,I get an error
"[OracleException] errcode: 1804, desc: Error while trying to retrieve text for error ORA-01804".
I got the same error for cx_oracle (via python). For this specific case ORACLE_HOME was missing in environment variables.
Set Oracle_home with Windows Cli (use your oracle folder):
setx ORACLE_HOME "C:\oracle\oc121\"
On some of the DB connections TNS_ADMIN is required also set that as well:
setx TNS_ADMIN "%ORACLE HOME%\network\admin"
I use OCCI in CentOS 7, and encounter the same issue, just add libociicus.so to LD_LIBRARY_PATH to resolve the issue.
You are receiving ORA-01804 by the database, the description of ORA-01804 is:
failure to initialize timezone information
Cause: The timezone information file was not properly read.
I was experiencing such trouble with C++ OCCI application which caught oracle::occi::SQLException when it was trying to connect to oracle db.
ORA-01804:
failure to initialize timezone information
Cause: The timezone information file was not properly read.
The reason was that my linux oracle client was missing some timezone related files in its $ORACLE_HOME directory.
The solution was to simply copy those files from another instance of oracle client.
Another possible reason: Binary have no permission to access the OCCI library ...
I encounter such situation due to my mistakenly setting mode of folder in which OCCI library is.
In my case, libociicus.so (can be found in the Oracle Instant Client) was missing.
Another trivial yet hard to determine cause for this might be that Oracle installation folder is incomplete. For me, a reason for this was that some process just (unsuccessfully) uninstalled Oracle client.
It was really tricky as bin folder from PATH env. var contained oci.dll (and lots of other DLL-s), but elsewhere under C:\oracle\11\ there were other files missing.
So: check that installation folder contains all required files!
I know this is an old question, but there are no answers can fix my case (oracledb package of nodejs, macOS).
but, again, I found a solution for myself.
The solution is that move libociei.dylib into /usr/locale/lib folder. That's it.
For me, it's because the version of my instant client and the database server is using a different version. So I had to match their version to solve this error. Apparently, Oracle can't read the DB timezone if their version is different.
The following isn't really a good solution. I'm not sure myself what made the deal. But for me the solution was to:
drop all other oracle clients from my PC
clear ORACLE_HOME and PATH from paths to dropped clients
restart the PC
After that the error was gone

Adwords, Python Import Script. MySQL goes fubar

I wrote a Python 2.7 script based on the Python examples from google Adwords on github, installed the MySQL Connector from MySQL Page itself under Connectors.
And started with creating the script, but I am not able to find the bug which is causing that MySQL stops insert data or not even goes into the function.
No error messages, even removed all try and catch. Same.
If you like to check it for yourself: http://pastebin.com/WEQqBNHB
I used 5 Connections, because the functions call each other and it seems like if while is used you need one connection for it seperated.
MySQL Syntax is okay, as phpmyadmin is telling me.
Everything works exept Adgroups_AD/Adgroups_Performance
Any Ideas?
It seems like that i even need to commit select query's in python.
That fixed the issue. dang.

How to connect to a SQL Server database in Anaconda

I'm quite new to Python and programming in general, so please bear with me. At my work I have Anaconda (Python vers 2.7) installed and would like to connect to a Microsoft SQL Server database, preferably with ODBC. Related to this task I have a number of questions:
Is it correct that I cannot connect to a SQL Server database using sqlite3 or sqlalchemy? That I need a module like pyodbc? A brief explanation of why this is the case would be much appreciated.
EDIT: Question related to installation of pyodbc in anaconda removed, since I figured this out (by reading Cannot Install Python Modules after Installing Anaconda)
Help is much appreciated! If any of my questions/any other specifics need to be cleared up, please don't hesitate to ask. Thanks
I do not use Anaconda, but I use various databases and ODBC. At first you can try if you have odbc module installed. It is a part of pywin32 package (http://sourceforge.net/projects/pywin32/files/) and is packed with ActiveState Python distribution. Other distribution can install it separately. Simply try:
import odbc
db = odbc.odbc('dsn/user/password')
You can also try with pyodbc you mentioned in question. There is precompiled version for Windows and I think it will work with your Anaconda environment. After installing try:
import pyodbc
db = pyodbc.connect('Driver={SQL Server Native Client 10.0};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;')
You can find more connection strings at http://www.connectionstrings.com/
EDIT:
It seems that you have problem with bitness of ODBC driver.
Try to run this program to see what sources are visible to ODBC manager:
import odbc
source = odbc.SQLDataSources(odbc.SQL_FETCH_FIRST)
while source:
print(source)
source = odbc.SQLDataSources(odbc.SQL_FETCH_NEXT)

How do I access an Oracle db without installing Oracle's client and cx_Oracle?

I have two RHEL servers running Python 2.4 and 2.6 separately. There is an Oracle database on the other server I need to access.
I was trying to install cx_oracle on my RHEL server but found out that the Oracle client must be installed first.
The problem is, I don’t have permission to install Oracle's client on both RHEL servers. On the same servers, a Perl program can connect to the Oracle db using:
DBI->connect("dbi:Oracle:host=myhost.prod.com;sid=prddb",'username','password')
Can Python do the same without installing cx_oracle and the Oracle client? Or are there any suggestions about how to write a module myself to do the same thing?
Thanks in advance!
An excerpt from https://forum.omz-software.com/topic/184/oracle-database:
There's no pure python client for Oracle and likely never will be. Even wonderful third-party toolsets like SQLalchemy still rely on cx_Oracle underneath to do the actual communication to the Oracle database servers.
—also, deciding by Google, the answer is no: there do not seem to be any pure Python Oracle clients in existence as of today.
Usually, all you need are the libraries, which don't necessarily require sudo rights. Extract them to a place the software will be able to read from and set the following environment variables accordingly:
ORACLE_HOME=path/to/where/you/extracted/libs
TNS_ADMIN=path/to/tnsnames.ora
I have had best luck skipping tnsnames, and just specifying the host, port, etc in the connection, but it's quite possible you'll need it for cx_oracle...I don't remember from when I used it ages ago.
if you don't want use cx_Oracle you should use expect scripting. ( for python pexpect). But you need to be carefully for handle all expectations.

What do I need to successfully run a website in my browser that executes Python scripts?

I currently simply have a local website on my Mac. I can view the webpage's HTMl and CSS and run the javascript functions in browser on my computer, but the next step I want to take is incorporating python scripts for accessing a MySQL database and returning results.
I am clearly new to this, and would love some guidance. Right now, on my computer, I have MySQL installed and I can run it in the terminal just fine. What else do I need as far as database and server equipment – if anything – to get some dynamic website running locally? My current, albeit incredibly limited, understanding is that I have a MySQL database stored on my machine that can be accessed through a Python script – also on my machine – and a link to this script in the HTML file. Is this even right, or do you recommend certain tutorials to fill in the gaps or teach me from the ground up?
I am sorry I am asking a lot; the few tutorials I have found have seemed to cover what I am hoping to do. Many thanks in advance.
Here you go. https://docs.djangoproject.com/en/1.4/intro/install/
Just follow the installation guide, and you'll be up and running in no time.
If you have MySQL installed on your machine along with Python, get a version of MySQLDb library for Python and have fun with it. Moreover, you can do almost any data operation with these combinations. If you want your website to go live (and do not wish to go through web frameworks) just look for a hosting plan that gives you a Python installed server access.

Categories