C#C
C#3y ago
Jibz

✅ cannot connect console dotnet project with microsoft SQL

I'm following this : https://learn.microsoft.com/en-us/azure/azure-sql/database/connect-query-dotnet-core?view=azuresql-mi

I'm running microsoft sql from docker. I can access my database from azure data studio by setting server as "localhost" so I tried to do the same in my code. My confusion is here
builder.DataSource = "<your_server.database.windows.net>";

setting "server" in azure data studio works so I thought it should work as well in code but it throws error when I do this:
builder.DataSource = "localhost";
or this
builder.DataSource = "localhost.database.windows.net";

What am i doing wrong?
This topic shows you how to use .NET to create a program that connects to a database in Azure SQL Database, or Azure SQL Managed Instance, and queries it using Transact-SQL statements.
Was this page helpful?