I'm writing a python script on Jupyter notebook on my Mac OS, and I'm trying to connect to a local DB that is located on my Parallels Windows operating system that is running from my external hard drive.
I've tried the following code:
import pyodbc
from sqlalchemy import create_engine
import urllib
import json
import requests
import pandas as pd
import codecs
import datetime
import pytz
import mysql.connector
from mysql.connector import Error
params = 'DRIVER={ODBC Driver 13 for SQL Server};' 'SERVER=local;' 'DATABASE=Totepro;'
params = urllib.parse.quote_plus(params)
db = create_engine('mssql+pyodbc:///?odbc_connect=%s' % params)
def get_new_race_data():
sql_get_data = '''
SELECT * FROM RaceRowReport
WHERE RaceKey = cur_race_key
'''
new_race_data = pd.read_sql_query(sql_get_data, db)
return new_race_data
get_new_race_data()
This is the output:
OperationalError: (pyodbc.OperationalError) ('HYT00', '[HYT00] [Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')
(Background on this error at: http://sqlalche.me/e/e3q8)
I have also tried the following in terms of adjusting the connection string:
SERVER=10.211.55.3
However I still got the same issue. I've turned off the firewall from windows, but still nothing. ..
Then I tried:
import mysql.connector
from mysql.connector import Error
connection = mysql.connector.connect(host='10.211.55.3',
database='Totepro')
and now I find myself with the following error:
ProgrammingError: 1045 (28000): Access denied for user ''@'localmac' (using password: NO)
Any assistance would be helpful.
Thanks
I assume you're trying to connect to MS SQL Server, though your question has contradictory information - parts of it refer to MSSQL, while other parts mention MySQL.
First you need to establish network connectivity with the guest. Access Parallels Windows localhost from Mac might be helpful with that. I'm guessing that while you try to use SERVER=local
, you don't actually have local
mapped to the guest VM. Once you ensure the guest VM uses "Shared networking" and find its public IP address (referred to as YOUR_VM_IP_ADDRESS from now on), check that you can ping it with
ping YOUR_VM_IP_ADDRESS
Then check that you can access the SQL Server's port (the default is 1433), using
nc -v YOUR_VM_IP_ADDRESS 1433
# -- or --
telnet YOUR_VM_IP_ADDRESS 1433
# shouldn't say "connection refused"
Ensure that you can connect using sqlcmd
(note that Windows authentication won't work when connecting from the macOS machine, you have to use login/password):
sqlcmd -S YOUR_VM_IP_ADDRESS -U username -P password
After the above tests succeed, you have a chance of coming up with the correct connection string and establishing the SQLAlchemy connection. This answer might help with that.