Azure 机器学习工作室:无法从 Azure SQL 数据库创建数据存储
Azure Machine Learning Studio: cannot create Datastore from Azure SQL Database
-
azure
-
azure-machine-learning-studio
-
azure-sql-database
-
azure-sdk-python
-
azure-machine-learning-service
我正在尝试从 Azure 机器学习工作室连接到 Azure SQL 数据库。基于https://docs.microsoft.com/en-us/python/api/azureml-core/azureml.core.datastore.datastore?view=azure-ml-py,似乎推荐的模式是使用Datastore.register_azure_sql_database方法创建Datastore,如下所示:
import os
from azureml.core import Workspace, Datastore
ws = Workspace.from_config() # asks for interactive authentication the first time
sql_datastore_name = "datastore_test_01" # any name should be fine
server_name = os.getenv("SQL_SERVERNAME" , "{SQL_SERVERNAME}") # Name of the Azure SQL server
database_name = os.getenv("SQL_DATABASENAME" , "{SQL_DATABASENAME}") # Name of the Azure SQL database
username = os.getenv("SQL_USER_NAME" , "{SQL_USER_NAME}") # The username of the database user.
password = os.getenv("SQL_USER_PASSWORD" , "{SQL_USER_PASSWORD}") # The password of the database user.
sql_datastore = Datastore.register_azure_sql_database(workspace = ws,
datastore_name = sql_datastore_name,
server_name = server_name,
database_name = database_name,
username = username,
password = password)
我很确定我已经正确设置了所有参数,从我的 SQL 数据库资源的 ADO.NET 连接字符串中复制了它们 --> 设置 --> 连接字符串:
Server=tcp:{SQL_SERVERNAME}.database.windows.net,1433;Initial Catalog={SQL_DATABASENAME};Persist Security Info=False;User ID={SQL_USER_NAME};Password={SQL_USER_PASSWORD};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;
但是,我收到以下错误:
Registering datastore failed with a 400 error code and error message 'Azure SQL Database Error -2146232060: Please check the correctness of the datastore information.'
我错过了什么吗?例如,防火墙规则?我还尝试将 Azure ML 计算资源的 public IP 地址添加到我的 SQL 数据库资源中允许的 IP 地址列表中,但仍然没有成功。
更新:将skip_validation = True
添加到Datastore.register_azure_sql_database
解决了问题。然后我可以用
查询数据
from azureml.core import Dataset
from azureml.data.datapath import DataPath
query = DataPath(sql_datastore, 'SELECT * FROM my_table')
tabular = Dataset.Tabular.from_sql_query(query, query_timeout = 10)
df = tabular.to_pandas_dataframe()
是 vnet 背后的数据存储?你运行上面的注册码在哪里?在同一个 vnet 后面的计算实例上?
这是描述连接到 vnet 背后的数据所需执行的操作的文档:
https://docs.microsoft.com/en-us/azure/machine-learning/how-to-enable-virtual-network#use-datastores-and-datasets
azure
azure-machine-learning-studio
azure-sql-database
azure-sdk-python
azure-machine-learning-service
我正在尝试从 Azure 机器学习工作室连接到 Azure SQL 数据库。基于https://docs.microsoft.com/en-us/python/api/azureml-core/azureml.core.datastore.datastore?view=azure-ml-py,似乎推荐的模式是使用Datastore.register_azure_sql_database方法创建Datastore,如下所示:
import os
from azureml.core import Workspace, Datastore
ws = Workspace.from_config() # asks for interactive authentication the first time
sql_datastore_name = "datastore_test_01" # any name should be fine
server_name = os.getenv("SQL_SERVERNAME" , "{SQL_SERVERNAME}") # Name of the Azure SQL server
database_name = os.getenv("SQL_DATABASENAME" , "{SQL_DATABASENAME}") # Name of the Azure SQL database
username = os.getenv("SQL_USER_NAME" , "{SQL_USER_NAME}") # The username of the database user.
password = os.getenv("SQL_USER_PASSWORD" , "{SQL_USER_PASSWORD}") # The password of the database user.
sql_datastore = Datastore.register_azure_sql_database(workspace = ws,
datastore_name = sql_datastore_name,
server_name = server_name,
database_name = database_name,
username = username,
password = password)
我很确定我已经正确设置了所有参数,从我的 SQL 数据库资源的 ADO.NET 连接字符串中复制了它们 --> 设置 --> 连接字符串:
Server=tcp:{SQL_SERVERNAME}.database.windows.net,1433;Initial Catalog={SQL_DATABASENAME};Persist Security Info=False;User ID={SQL_USER_NAME};Password={SQL_USER_PASSWORD};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;
但是,我收到以下错误:
Registering datastore failed with a 400 error code and error message 'Azure SQL Database Error -2146232060: Please check the correctness of the datastore information.'
我错过了什么吗?例如,防火墙规则?我还尝试将 Azure ML 计算资源的 public IP 地址添加到我的 SQL 数据库资源中允许的 IP 地址列表中,但仍然没有成功。
更新:将skip_validation = True
添加到Datastore.register_azure_sql_database
解决了问题。然后我可以用
from azureml.core import Dataset
from azureml.data.datapath import DataPath
query = DataPath(sql_datastore, 'SELECT * FROM my_table')
tabular = Dataset.Tabular.from_sql_query(query, query_timeout = 10)
df = tabular.to_pandas_dataframe()
是 vnet 背后的数据存储?你运行上面的注册码在哪里?在同一个 vnet 后面的计算实例上? 这是描述连接到 vnet 背后的数据所需执行的操作的文档: https://docs.microsoft.com/en-us/azure/machine-learning/how-to-enable-virtual-network#use-datastores-and-datasets