1+ {
2+ "metadata" : {
3+ "language_info" : {
4+ "codemirror_mode" : {
5+ "name" : " ipython" ,
6+ "version" : 3
7+ },
8+ "file_extension" : " .py" ,
9+ "mimetype" : " text/x-python" ,
10+ "name" : " python" ,
11+ "nbconvert_exporter" : " python" ,
12+ "pygments_lexer" : " ipython3" ,
13+ "version" : " 3.8.5"
14+ },
15+ "orig_nbformat" : 2 ,
16+ "kernelspec" : {
17+ "name" : " python385jvsc74a57bd09ceeaccb2d4b8fc120d52b4319c20d729c878e30972ae0f296691445edd93f69" ,
18+ "display_name" : " Python 3.8.5 32-bit"
19+ }
20+ },
21+ "nbformat" : 4 ,
22+ "nbformat_minor" : 2 ,
23+ "cells" : [
24+ {
25+ "source" : [
26+ " # Connect to Azure SQL Database using Python and Jupyter Notebook"
27+ ],
28+ "cell_type" : " markdown" ,
29+ "metadata" : {}
30+ },
31+ {
32+ "source" : [
33+ " ## Open the connection"
34+ ],
35+ "cell_type" : " markdown" ,
36+ "metadata" : {}
37+ },
38+ {
39+ "cell_type" : " code" ,
40+ "execution_count" : null ,
41+ "metadata" : {},
42+ "outputs" : [],
43+ "source" : [
44+ " import pyodbc\n " ,
45+ " \n " ,
46+ " # Establish the connection\n " ,
47+ " server = '<server>.database.windows.net'\n " ,
48+ " database = '<database>'\n " ,
49+ " username = '<username>'\n " ,
50+ " password = '<password>'\n " ,
51+ " driver= '{ODBC Driver 17 for SQL Server}'\n " ,
52+ " conn = pyodbc.connect('DRIVER=' + driver + ';SERVER=' +\n " ,
53+ " server + ';PORT=1433;DATABASE=' + database +\n " ,
54+ " ';UID=' + username + ';PWD=' + password)\n " ,
55+ " \n " ,
56+ " print(conn)"
57+ ]
58+ },
59+ {
60+ "source" : [
61+ " ## Close the connection"
62+ ],
63+ "cell_type" : " markdown" ,
64+ "metadata" : {}
65+ },
66+ {
67+ "cell_type" : " code" ,
68+ "execution_count" : null ,
69+ "metadata" : {},
70+ "outputs" : [],
71+ "source" : [
72+ " conn.close()"
73+ ]
74+ }
75+ ]
76+ }
0 commit comments