Nelson Gomes Matias
Nelson Gomes Matias

Reputation: 1997

Azure Machine Learning Write output to Azure SQL Database

I am using Azure Machine Learning to clustering data.

The input data is from an Azure SQL Database, and it works fine. At the end of everything I want to write the output to a table in the same Azure SQL Database, but I get this error:

Error: Error 1000: AFx Library library exception: 
Sql encountered an error: Login failed for user

Anyone any idea? Thank you very much!

Upvotes: 0

Views: 1592

Answers (2)

Nelson Gomes Matias
Nelson Gomes Matias

Reputation: 1997

Find the issue!

I needed to create an specific user with this SQL code:

CREATE USER AMLApplicationUser WITH PASSWORD = '************';

and then add the user to these roles on the database I want to write.

ALTER ROLE db_datareader ADD MEMBER AMLApplicationUser;
ALTER ROLE db_datawriter ADD MEMBER AMLApplicationUser;

I guess only the datawriter role is enough, but I needed datareader too.

So in conclusion, seems that database admin role can be used to read data, but not to write data from AML.

Thank you for your help!

Upvotes: 0

Alberto Morillo
Alberto Morillo

Reputation: 15608

Please follow the instructions and examine the examples provided here to properly use the Export Data module to save the data of ML to Azure SQL Database.

How to Export Data to an Azure SQL Database

  • Add the Export Data module to your experiment. You can find this module in the Data Input and Output group in the experiment items list in Azure Machine Learning Studio.

  • Connect it to the module that produces the data that you want to export to Azure SQL DB.

  • For Data destination, select Azure SQL Database. This option supports Azure SQL Data Warehouse as well.

  • Set the following options specific to Azure SQL Database or Azure SQL Data Warehouse.

    Database server name
    Type the server name that is generated by Azure. Typically it has the form <generated_identifier>.database.windows.net.

    Database name
    Type the name of a database on the server you just specified.The database must already exist; the Export Data cannot create it.

    Server user account name
    Type the user name of an account that has access permissions for the database.

    Server user account password
    Provide the password for the specified user account.

    Comma-separated list of columns to be saved
    Type the names of the columns in the experiment that you want to write to the database.

    Data table name
    Type the name of the table where data will be stored.

    For Azure SQL Database, if the table does not exist, it will be created. For Azure SQL Data Warehouse, the table must already exist and have the correct schema, so be sure to create it in advance.

    Comma-separated list of datatable columns
    Type the names of the columns as you wish them to appear in the destination table. The columns should correspond in order with the column names that you list in Comma-separated list of columns to be saved.

    if you are writing to Azure SQL Data Warehouse, the columns names must match those already in the destination table schema.

    Number of rows written per SQL Azure operation
    Indicate how many rows should be written to the destination table in each batch. By default, the value is set to 50, which is the default batch size for Azure SQL Database. However, you should increase this value if you have a large number of rows to write.

    TIP:

    For Azure SQL Data Warehouse, we recommend that you set this value to 1. If you use a larger batch size, the size of the command string that is sent to Azure SQL Data Warehouse can exceed the allowed string length, causing an error.

  • If you don't want to write new results each time you run the experiment, select the Use cached results option. If there are no other changes to module parameters, the experiment will write the data the first time the module is run, and thereafter not perform writes.

    However, a write will always be performed if any parameters have been changed in Export Data that would change the results.

  • Run the experiment.

Upvotes: 2

Related Questions