+ All Categories
Home > Software > Using PowerShell with Python and SQL Server

Using PowerShell with Python and SQL Server

Date post: 12-Apr-2017
Category:
Upload: idera-software
View: 63 times
Download: 0 times
Share this document with a friend
17
Using PowerShell with Python & SQL Server February 22, 2017 Maximo Trinidad
Transcript
Page 1: Using PowerShell with Python and SQL Server

Using PowerShell with Python & SQL Server

February 22, 2017Maximo Trinidad

Page 2: Using PowerShell with Python and SQL Server

Python SQL Connectors

Understanding Your Environment

PowerShell and SQL Server

Questions3

12

4

1

Reference Information5

Page 3: Using PowerShell with Python and SQL Server

Understanding Your Environment

2

You’ve got to be kidding!

Page 4: Using PowerShell with Python and SQL Server

Top demand programming languageshttps://www.techworm.net/2017/02/top-9-demand-programming-languages-2017.html

1. SQL 2. Java3. Python4. Javascript5. C++6. C#7. Perl8. iOS 9. PHP

3

Page 5: Using PowerShell with Python and SQL Server

Understanding Your Environment

- Install component in both Windows and Linux- PowerShell Open Source- Python 2.7 (By Default) or 3.x - Python Tcl/Tk packages- Python SQL Connectors- Use OneDrive

- On Bash access (/mnt/c/Users/#username#/OneDrive)- On Linux access Windows shared folders

4

Page 6: Using PowerShell with Python and SQL Server

Understanding Your Environment

- You're New to Linux- Go “Bash-On-Ubuntu-On-Windows”

- Install "Ubuntu Desktop" - PowerShell

- Python- Cross-Platform Editor

- VS Code lightweight Multi-language editor- Other editors

-Sublime-Brains PyCharm (Robust Python Editor Windows and Linux)

*Use Windows Editors to create code

5

Page 7: Using PowerShell with Python and SQL Server

Demo 16

Page 8: Using PowerShell with Python and SQL Server

PowerShell and SQL Server

- Connecting to SQL Server for scripting- Two ways: SQLPS module and SMO

- Used only Windows Desktop (or Server)*Not possible on Linux systems

- Access PowerShell from SSMS- Python with PowerShell for data collection

- Possibility of Cross-platform solutions- Take advantage of .NET objects in Linux

7

Page 9: Using PowerShell with Python and SQL Server

PowerShell and SQL Server

8

Page 10: Using PowerShell with Python and SQL Server

PowerShell and SQL Server

9

Page 11: Using PowerShell with Python and SQL Server

Connecting to SQL Server with Python

- Choose a Python version- Use “sudo Update-Alternatives” command

- # update-alternatives --list python

- Two SQL Connectors- pyodbc- pymssql

- Connectors Behaviour- pyodbc and pymssql can connect to

- Windows local and Multi-instance SQLServer- Linux only single instance

10

Page 12: Using PowerShell with Python and SQL Server

Demo 2Connecting to SQL Server with Python SQL connectors:-SQL Sample:Sampledb1SQLScript.sql

-Python Sample:QueryDataSample_pyodbc.pyQueryDataSample_pymssql.pyGuiSQLDataGrid01.pyReadCSVfileToGrid.pySampleMessageBox01.py

-PowerShell with Python :SamplePoshSQLPython2_Bash.ps1

11

Page 13: Using PowerShell with Python and SQL Server

Questions12

Page 14: Using PowerShell with Python and SQL Server

Reference Information

13

PowerShell Open Source: https://github.com/PowerShell/PowerShell

Python 3.5.2 (both Windows and Linux): https://www.python.org/download/releases/3.2.5/

Python Tcl/Tk: http://www.tcl.tk/

Python SQL Server ODBC connector (pyodbc): https://github.com/mkleehammer/pyodbc Python Microsoft SQL Server connector (pymssql): http://pymssql.org/en/stable/intro.html

MaxtBlog post “Windows 10 Bash and PowerShell Redux”: http://www.maxtblog.com/2017/01/windows-10-bash-and-powershell-redux/

Bash for Windows 10: https://blogs.msdn.microsoft.com/commandline/learn-about-bash-on-windows-subsystem-for-linux/

*Important link: https://blogs.msdn.microsoft.com/commandline/2016/11/17/do-not-change-linux-files-using-windows-apps-and-tools/

Page 15: Using PowerShell with Python and SQL Server

Don’t forget to check out the

previously recorded Geek Sync

webcasts to learn more about

PowerShell and SQL Server.

Thank You!

https://www.idera.com/events/geeksync

Page 16: Using PowerShell with Python and SQL Server

Maximo Trinidad

Email: [email protected]

Twitter: @maxtrinidad

Contact information:

Page 17: Using PowerShell with Python and SQL Server

Head over to IDERA.com to

download any of our product trials

free for 14-days.

Free Trials


Recommended