Search code examples
asp.net-coreazure-sql-databaseazure-sql-server

How to configure connection string for ASP.NET Core and azure, netcoreapp3.1, with VS2019?


I followed the basic example tutorial from Microsoft on how to publish an ASP.NET Core app to Azure with visual studio (https://learn.microsoft.com/pt-br/aspnet/core/tutorials/publish-to-azure-webapp-using-vs?view=aspnetcore-3.1)

There is this part where I configure the Azure SQL Database entering the administrator username and password. After that, I have to configure the database connection string. They say "Best practice is to avoid using the same details as the admin username & password used in the previous step."

But, I couldn't figure out how to use a different username and password than the administrator ones. How can I create a connection string which uses a different username/password? At the Azure control panel, I see the connection string with the admin username already. Can I create another connection string for other users?

This is the one that works, with admin user/pass

Data Source=tcp:xxxwebapplicationdbserver.database.windows.net,1433;Initial Catalog=xxx;User Id=xxx@xxxwebapplicationdbserver;Password={mypass}


Solution

  • You need to create a new user on your Azure SQL database with the minimum required permissions for your app. That will give you a username and password that you can use in your deployed app.

    The basic script is:

    CREATE LOGIN login_name WITH PASSWORD = 'strong_password';
    GRANT SELECT ON OBJECT::HumanResources.Employee TO Larry;