Cannot connect to Sqlserver from python script in windows XP - python

I am using a windows XP machine that is using Microsoft SQl Server Enterprise Edition version 8.00.194, SQL-DMO version: 8.00.02 and ODBC version : 03.52.0000. I have another database of MySql on some other machine in the same network and I want to retrieve the data from that database to my XP machine's Sqlserver database. For this purpose I am trying to check whether I can connect to the local machine with my following python script (I use the pymssql library for this purpose):
import pymssql
con1=pymssql.connect(server="localhost:1433",user="XXXX",password="XXXX",database="XXXX")
print con1
con1.close()
I have purposefully removed the original username, password and db name. After running the above script I get the error:
Traceback (most recent call last):
File "D:\py_script_data_1st\1.py", line 9, in <module>
con1=pymssql.connect(server="localhost:1433",user="xxxx",password="xxxx",database="xxxx")
File "pymssql.pyx", line 636, in pymssql.connect (pymssql.c:10178)
OperationalError: (20009, 'DB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is unavailable or does not exist\nNet-Lib error during Unknown error (10061)\n')
I have searched extensively but did not get any working solution for that error. What I got was to open the port 1433. I have opened the sqlserver.exe instance in my firewall by following the instructions given https://support.microsoft.com/en-us/kb/841251
When I do telnet on port 1433 by using:
telnet localhost 1433
I get error that says could not connect to port 1433.
I would also like to add that the database on which I am working is of a library system. There are two machines on which issues/returns trasactions of the book takes place. So the other machine (which is also a windows XP machine) connects to the server machine using a software that uses netbios-ssn for the communication. I found this fact by using netstat command. Here is the output of that command:
TCP issue:netbios-ssn 192.168.48.45:2211 ESTABLISHED
TCP issue:netbios-ssn 192.168.48.48:3456 ESTABLISHED
I am extremely confused about these facts. I don't understand how can other machine access server's database using netbios-ssn port?
So, I have effectively two questions and solution to any one of them can help me out.
What is the solution for the problem of the python script ?
If the first problem cannot be solved, how can I achieve the connection to the database using netbios-ssn port?
Please help and feel free to ask any further information if you want.

Related

How do I connect to a MySQL Database in Python with a RaspberryPi

I'm a student and I'm trying to write some sensor values into a MySQL database.
As IDE I'll be using Inteliji.
First off I started by installing the database Plug-in.
This was done successfully
Next I tried to connect to the data base (see figure below)
Figure of successful connection
Now The next thing I want to do is use a MySQL connector.
Therefore I've installed MySQL onto the r-PI and used following code to implement it.
import mysql.connector
print("Step 1")
cnx = mysql.connector.connect(user='a21ib2a01',
password='secret',
host='mysql.studev.groept.be',
database='a21ib2a01')
Print("Step 2")
When now I run my code the terminal will output:
Step1
For some reason I don't know; the connect function always times my program out with the next occurring errors:
mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on 'mysql.studev.groept.be:3306' (110 Connection timed out)
So does anyone know why my connection is successful but I can't connect to it?
Long story short what am I doing wrong and how do I fix this?
Thanks in advance!
Your timeout means the network on your rPi cannot reach -- cannot find a route to -- your MySQL host mysql.studev.groept.be.
If you do traceroute mysql.studev.groept.be in a shell in the rPi you may see what's wrong.
When in a shell on your rPi, can you ssh to any machine in your uni's network? If so, you might be able to use ssh port-forwarding to get a route to the database server.
Do you run intelliJ on the rPi directly, or on your laptop? If you run it on the laptop, it looks like the laptop can find a route to your server but the rPi cannot.
(If this were my project, I'd install a MySQL server on my laptop to reduce the network-engineering hassles of connecting through multiple hops involving a VPN.)

Python MySQL-Connector failing to connect intermittently on Windows VPS

I am scraping data using a Windows VPS. I am using Python MySQL-Connector to upload this scraped data to a Linux dedicated server.
import mysql.connector
mydb = mysql.connector.connect(
host="...",
user="...",
password="...",
database="...",
connection_timeout=60
)
mycursor = mydb.cursor()
About 25% of the time this fails, or takes more than twenty seconds. When it fails I get a 10060 error. Is the problem more likely to be with my Linux server or more likely my Windows VPS? Help sincerely appreciated. Here is the error message:
2055: Lost connection to MySQL server at '[IP]:3306', system error: 10060 A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
This error is likely ralated to slow mysql database server, so you could do following:
Increase your connection_timeout to higher value i.e. 600.
Configure settings that are responsible for database server perormance (i.e. see this presentation - https://www.oracle.com/technetwork/community/developer-day/mysql-performance-tuning-403029.pdf) especially set mysql RAM usage server (1/2 of total system RAM - variable innodb_buffer_pool_size (set it in my.cnf))
Ensure that your closes cursor after your finished to use it, call mycursor.close.
Increase if possible resources (CPU, RAM, more faster disk drive) of a system with your database server.
Looking at the error message, I suspect this is caused by a port being blocked (the default TCP/IP port of the MySQL server is 3306).
Check if the port 3306 is busy:
netstat -tulpn | grep 3306
then try to free that port before running your app again.

updating to newest ubuntu has made it so I can't access mysql...what do I do?

I updated to the latest ubuntu distribution and now I can't access my mysql databases! I used to log in with root without a password, and now when I try to log in I don't have access because I don't know the password.
There are a lot of questions that are similar to this online. I followed a few of them and the furthest I get is this error:
(2002, "Can't connect to local MySQL server through socket
'/var/run/mysqld/mysqld.sock' (2)")
I tried to follow /var/run/mysqld/mysqld.sock and I don't have a mysqld folder.
So I imagine that's a problem. Other questions I've seen on here point to /etc/mysql/...mysql.cnf.
I have that file but the file doesn't contain anything about a socket.
I'm totally at a loss for how I get access to my databases that I've built! Please help! What should I do?
From terminal:
sudo service mysqld start
Error show that the mysql server is not running on your ubuntu machine.

Python mod_wsgi database connection not working

I've installed Postgres, mod_wsgi and python3.5 on a centos system. I've tested the connection and it works fine both in the interactive Python shell as well as the development application (it's a Pyramid app so it's the dev server from that).
I'm getting the following error:
postgresql.exceptions.ClientCannotConnectError: could not establish connection to server
CODE: 08001
LOCATION: CLIENT
CONNECTION: [failed]
failures[0]:
socket('127.0.0.1', 5432)
Traceback (most recent call last):
File "/var/www/wsgi/lib/python3.3/site-packages/postgresql/protocol/client3.py", line 136, in connect
self.socket = self.socket_factory(timeout = timeout)
File "/var/www/wsgi/lib/python3.3/site-packages/postgresql/python/socket.py", line 64, in __call__
s.connect(self.socket_connect)
PermissionError: [Errno 13] Permission denied
The above exception was the direct cause of the following exception:
postgresql.exceptions.ConnectionRejectionError: Permission denied
CODE: 08004
LOCATION: CLIENT
CONNECTOR: [Host] pq://username:***#localhost:5432/db_name
category: None
DRIVER: postgresql.driver.pq3.Driver
I spent some time looking at the mod_wsgi documentation and found there is a possible issue with sockets. However, I've already implemented that change (and the corresponding error from apache vanished).
My assumption is that it's a socket error still as the connection sting works fine elsewhere in the same Python install and even within the dev setup.
Can anybody point me in the right direction from here please?
Even if you set the database connect string to an IP address, if it is 127.0.0.1, I have encountered PostgreSQL database connectors which will try and optimise things and connect via the local UNIX socket instead. If the user that your code runs under with mod_wsgi cannot access that UNIX socket for accessing PostgreSQL it will fail with a permissions error.
I can't remember whether it was py-postgresql module that I saw this with, but did hit it a couple of weeks ago with on of the PostgreSQL database modules.
Try replacing 127.0.0.1 with the actual host name or proper IP address.

Cant Connect to remote MS SQL server using PYODBC on Windows 7 in Python

So I am having some issues trying to connect to my server that is hosted on my network but on a different computer to the program I am trying to run. I have checked and both computers are on the same domain. I am coding in python and using PYODBC to make the connection.
The connect line is as follows:
connectLine = 'DRIVER={SQL Native Client};SERVER='+configValues['host']+';DATABASE='+configValues['db']+';UID='+configValues['user']+';PWD='+configValues['passwd']
db = pyodbc.connect(connectLine)
Now that works when the server is on the same computer as the program, but when I try to connect to the server on my actual server it doesnt work. I am running MicrosoftSQL Express 2005 on Windows SBS 2003 and the computer running the program is running Windows 7 with the program coded in Python 2.7
This is the output of the program, I have it printing the connect line.
DRIVER={SQL Native Client};SERVER=192.168.1.103\OSBORNE;DATABASE=vpmser;UID=massEmailer;PWD=cogbutfeswas5836;
Traceback (most recent call last):
File "E:\Mass Emailer\massEmailer.py", line 56, in <module>
db = pyodbc.connect(connectLine)
Error: ('08001', '[08001] [Microsoft][SQL Native Client]SQL Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF]. (-1) (SQLDriverConnectW); [HYT00] [Microsoft][SQL Native Client]Login timeout expired (0); [08001] [Microsoft][SQL Native Client]An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (-1)')
Some possibilities:
(1) About this part of your connection string: SERVER=192.168.1.103\OSBORNE; ... part of the definitely-non-generic error message says """Error Locating Server/Instance Specified"""
A note from connectionstrings.com:
"""Are you using SQL Server 2005 Express? Don't miss the server name syntax Servername\SQLEXPRESS where you substitute Servername with the name of the computer where the SQL Server 2005 Express installation resides."""
If OSBORNE is not the name of the remote server, what is it? Why do you include an IP address?
Perhaps you should have OSBORNE\SQLEXPRESS instead of 192.168.1.103\OSBORNE
(2) Down the end of the error message, it says """When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections.""" ... Have you checked that (a) SQL Server Express supports remote connections (b) it is configured to allow remote connections?
(3) Can you access the database remotely using (a) a remote logon to the server machine with the userid and password that you are using (b) a query tool that you run on the client machine and uses a DSN to point to the remote machine & database? If so, how do the connection parameters differ from what you have in your connection string?

Categories

Resources