Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jupyter Notebook kernel dying when trying to connect to SQL Server with odbc #487

Closed
dpezim opened this issue Nov 15, 2018 · 6 comments
Closed

Comments

@dpezim
Copy link

dpezim commented Nov 15, 2018

Environment

  • Python: 3.6.4
  • pyodbc: 4.0.23
  • OS: MacOS Mojave 10.14
  • DB: SQL Server
  • driver: ODBC Driver 17 for SQL Server

Issue

I am currently trying to connect to SQL Operations Studio (SQL Server for mac) through Jupyter Notebook. In Terminal, I use this code to install the driver:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release brew update brew install --no-sandbox msodbcsql17 mssql-tools

And I used this command (from this question: ) to fix a driver problem:

sudo ln -s /usr/local/etc/odbcinst.ini /etc/odbcinst.ini sudo ln -s /usr/local/etc/odbc.ini /etc/odbc.ini

Now I try to run the following code in Jupyter:

`import pyodbc

cnxn = pyodbc.connect('driver={ODBC Driver 17 for SQL Server},
server=###,
database=###,
uid=###,
pwd=###')

cur = cnxn.cursor()

db_cmd = "SELECT TOP (10) * FROM [dbo].[ChargePoints]"

res = cur.execute(db_cmd)`

Then get this error message: "The kernel appears to have died. It will restart automatically." I've tested it and I know it is dying on the second line, pyodbc.connect. I have never tried to do SQL queries from python before so I have no clue where to go from here.

@v-chojas
Copy link
Contributor

@dpezim
Copy link
Author

dpezim commented Nov 15, 2018

I'm having trouble getting that trace to work. Bit of extra information though:

The Terminal is giving me this error:
libc++abi.dylib: terminating with uncaught exception of type std::runtime_error: collate_byname::collate_byname failed to construct for UTF-8

@v-chojas
Copy link
Contributor

That could be related to microsoft/homebrew-mssql-release#18 ,

@dpezim
Copy link
Author

dpezim commented Nov 18, 2018

@v-chojas this ended up being correct. I appended the bash_profile with the UTC-8 locale and it fixed the issue. Thanks!

@dpezim dpezim closed this as completed Nov 18, 2018
@vengal21
Copy link

vengal21 commented May 7, 2024

import pandas as pd
from sqlalchemy import create_engine

engine = create_engine("mysql+pymysql://{user}:{pw}@localhost/{db}"
.format(user = "root", # user
pw = "vengalrao21@", # passwrd
db = "spam"))
sql = 'SELECT * FROM spam'
spam = pd.read_sql_query(sql, engine).convert_dtypes()
spam.shape

OperationalError: (pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on '@localhost' ([Errno 11003] getaddrinfo failed)")
i have facing this issue during the connection of sql and juypter notbook

@v-chojas
Copy link
Contributor

v-chojas commented May 7, 2024

Look up what error 11003 is, and you should probably start a new issue because everything else in the previous comments here is irrelevant to your situation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants