Windows 10: Unable to connect to external database from sql server python script-Python Services

Discus and support Unable to connect to external database from sql server python script-Python Services in Windows 10 Software and Apps to solve the problem; Trying to connect to an external database using python in an SQL stored procedure but seems like sqlalchemy is unable to connect to the external... Discussion in 'Windows 10 Software and Apps' started by rodney kaweesa, Jan 27, 2023.

  1. Unable to connect to external database from sql server python script-Python Services


    Trying to connect to an external database using python in an SQL stored procedure but seems like sqlalchemy is unable to connect to the external database. But we i run the script outside SQL serverSSMS it works perfectly.I have granted app containers and the launchpad account full rights and disabled outbound firewall rules but it is still failing.It returns an error: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions'Which other permissions do have to gran

    :)
     
    rodney kaweesa, Jan 27, 2023
    #1
  2. Brink Win User

    SQL Server + Python — What’s new


    Source: SQL Server + Python s new | SQL Server Blog
     
    Brink, Jan 27, 2023
    #2
  3. Simple Python Scripts

    Some Python Database Scripts

    Here are some Python Sqlite Database Scripts.

    You need the sqlite3 module installed,
    (but it's normally part of the initial Python install package)

    This first script creates the DATABASE and TABLE:

    Code: #!/usr/bin/python import sqlite3 try: #Here is where we create the database var_connection = sqlite3.connect("linux_database.db") #Now we create the cursor for access var_cursor = var_connection.cursor() #Now we create a database table var_cursor.execute('''CREATE TABLE linux_table(distro VARCHAR(15), version VARCHAR(5), type VARCHAR(10))''') var_connection.commit() var_connection.close() print "" print "linux_database DATABASE has been created" print "distro_table TABLE has been created" print "" except (ImportError, RuntimeError, TypeError, NameError): print "" print "Error, exception thrown" print ""[/quote] Image of this script running on my system:


    Unable to connect to external database from sql server python script-Python Services [​IMG]



    This next script inserts pre-defined data into the newly created table.
    The pre-defined data is contained within multiple TUPLES and the
    tuples are contained within a LIST.

    Code: #!/usr/bin/python import sqlite3 try: #Here is where we connect to the database var_connection = sqlite3.connect("linux_database.db") #Now we create the cursor for access var_cursor = var_connection.cursor() var_data = [ ('Gentoo', '2010', 'rolling'), ('Arch', '2010', 'rolling'), ('Slackware', '13.0', 'fixed'), ('Fedora', '12.0', 'fixed'), ('Debian', '5.0', 'fixed'), ('Ubuntu', '9.10', 'fixed'), ('openSUSE', '11.3', 'fixed'), ('Mandriva', '2010', 'fixed'), ('Mint', '8.0', 'fixed'), ('PCLinuxOS', '2010', 'rolling'), ] var_cursor.executemany('''INSERT INTO linux_table(distro, version,type) VALUES(?, ?, ?)''', var_data) var_connection.commit() var_connection.close() print "" print "Data has been input successfully" print "" except (ImportError, RuntimeError, TypeError, NameError): print "" print "Error inputing data" print ""[/quote] Again, here is the script running on my system:


    Unable to connect to external database from sql server python script-Python Services [​IMG]



    This final script sends a query to the database and displays the result.

    Code: #!/usr/bin/python import sqlite3 try: #Here is where we create the database var_connection = sqlite3.connect("linux_database.db") #Now we create the cursor for access var_cursor = var_connection.cursor() var_cursor.execute('''SELECT distro, version, type FROM linux_table ORDER BY distro''') print "" column_width = 15 for column_description in var_cursor.description: print column_description[0].ljust(column_width) , print "" print "-" * 45 var_index = range(len(var_cursor.description)) #Loop through the cursor dataset to extract data for row in var_cursor: for index in var_index: var_value = str(row[index]) print var_value.ljust(column_width) , print "" var_connection.commit() var_connection.close() print "" except (ImportError, RuntimeError, TypeError, NameError): print "" print "Error, selecting data to be displayed" print ""[/quote]
    Here is the script output:


    Unable to connect to external database from sql server python script-Python Services [​IMG]



    Some basic database functions in Python.
    It's a simple into which you can build on.
    Have Fun with it!! *Wink Unable to connect to external database from sql server python script-Python Services ;)
     
    regexorcist, Jan 27, 2023
    #3
  4. Hanifa21 Win User

    Unable to connect to external database from sql server python script-Python Services

    SQL Server 2019's python via Azure Data Studio

    Hi,

    We are building a ML solution using SQL Server Machine Learning services ? We understand that you can invoke the SQL instance python via commands like this.

    '

    The above commands will run in the SQL Server. However, this is not ideal for a development scenario. The idea is that we develop via Azure Data Studio and finally copy and pasta the codes via the sp_execute_external_script. However, we are facing an issue here.

    In the SQL Server, the python environment comes from here.

    C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\PYTHON_SERVICES while I am not able to launch a Azure Data Studio's python kernel from here. I tried changing the kernel using this link.

    Notebooks with Python Kernel in Azure Data Studio - Azure Data Studio

    Shown here.
    Unable to connect to external database from sql server python script-Python Services b1c7153b-52ae-4e46-a926-9b126e3953ab?upload=true.png


    However, I am not able to launch the python kernel anymore.

    .
     
    Hanifa21, Jan 27, 2023
    #4
Thema:

Unable to connect to external database from sql server python script-Python Services

Loading...
  1. Unable to connect to external database from sql server python script-Python Services - Similar Threads - Unable connect external

  2. Unable to connect to external database from sql server python script-Python Services

    in Windows 10 Gaming
    Unable to connect to external database from sql server python script-Python Services: Trying to connect to an external database using python in an SQL stored procedure but seems like sqlalchemy is unable to connect to the external database. But we i run the script outside SQL serverSSMS it works perfectly.I have granted app containers and the launchpad account...
  3. SQL Server Database Connectivity Issues

    in Windows 10 Gaming
    SQL Server Database Connectivity Issues: Not sure if this is the appropriate place to ask, but I currently use MS SQL Server Management Studio v18.10 for work. Whenever I'm on WiFi, I have no issues connecting to SQL Server databases, but as soon as I plug in my ethernet cable, I can't connect and I get timeout...
  4. SQL Server Database Connectivity Issues

    in Windows 10 Software and Apps
    SQL Server Database Connectivity Issues: Not sure if this is the appropriate place to ask, but I currently use MS SQL Server Management Studio v18.10 for work. Whenever I'm on WiFi, I have no issues connecting to SQL Server databases, but as soon as I plug in my ethernet cable, I can't connect and I get timeout...
  5. SQL Server Database Connectivity Issues

    in Windows 10 Customization
    SQL Server Database Connectivity Issues: Not sure if this is the appropriate place to ask, but I currently use MS SQL Server Management Studio v18.10 for work. Whenever I'm on WiFi, I have no issues connecting to SQL Server databases, but as soon as I plug in my ethernet cable, I can't connect and I get timeout...
  6. Windows Terminal and Python scripts?

    in Windows 10 Ask Insider
    Windows Terminal and Python scripts?: The new Windows Terminal is so beautiful and well done that I completely switched over to it, but the only thing that bugs me is still seeing the basic console window when running a Python script by double clicking on it... I did manage to make a profile for Python console,...
  7. Python Error in Main Script

    in Windows 10 Installation and Upgrade
    Python Error in Main Script: Hi, Can anybody help me i am getting Python Error in main Script, https://answers.microsoft.com/en-us/windows/forum/all/python-error-in-main-script/e606f84e-b2d8-4a8b-a94a-6bf55a1870b9
  8. MTP Python script

    in Windows 10 Ask Insider
    MTP Python script: I want to run a Python script using a MTP path (an external device). How can I write to it? submitted by /u/Geekest07 [link] [comments] https://www.reddit.com/r/Windows10/comments/f2g8ao/mtp_python_script/
  9. python script does not run from commandline

    in Windows 10 Customization
    python script does not run from commandline: hello, I'm having problems suddenly running .py scripts from the command line. CMD Before, *.py was associated with python.exe The association was created during python installation, associating python scripts .py with the proper executable. With the proper association...
  10. SQL Server + Python — What’s new

    in Windows 10 News
    SQL Server + Python — What’s new: Python is one of the most popular and fastest-growing languages used today. Pyodbc (Python-SQL Server Connector) is an open source Python module maintained by Michael Kleehammer that uses ODBC Drivers to connect to SQL Server. It allows you to connect from the platform of...