Connection to MySQL database in GhPython component

Hi guys,

I want to connect Grasshopper to MySQL database. I want to have the outcome of a sqlquery as output of the GhPython component.

import clr
from System.Data import *

TheConnection = SqlClient.SqlConnection("Server=localhost\\phpMyAdmin,3306;database=w43_anchors_towing_moong_equipment;trusted_connection=True")

MyAction = SqlClient.SqlCommand("SELECT File_path FROM w43 WHERE Weight BETWEEN 40 AND 80 ORDER BY Name", TheConnection)
MyReader = MyAction.ExecuteReader()

while MyReader.Read():
    print MyReader[0]


This what i have now. Python gives the following Error:

Runtime error (SqlException): A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 0 - An established connection was aborted by the software in your host machine.)


*line 7, in script* 

I have tried to change the servername in multiple ways, change the trustedconnection to a password and a username. I checked the query in MySQL and it works fine.

Really hope u can help me guys! Thanks in advance.

Here’s my guess…

MySQL and MsSQL are not the exact same thing. While I didn’t try recently any of these technologies, when I tried I remember that you need to use the binding/connector for MySQL, if using MySQL.

As you can see, the import is MySql.Data.MySqlClient.MySqlConnection, not System.Data.SqlClient.SqlConnection, which is MsSql.

Another option is that you bind to a MsSql server, not a MySQL one. More info here:

This is all technology that is not developed by Robert McNeel & Associates.



Giulio Piacentino
for Robert McNeel & Associates