Given the following connection string, I can connect to the MSSQL server from VS Code SQL Server extention and JetBrains Data Grip:
"Server=127.0.0.1,1433;User ID=sa;Password=P@ssw0rd;MultipleActiveResultSets=true;TrustServerCertificate=True"
However, when the app is run using Azure Function Core Tools, an error is returned for the following code:
services.AddScoped<IDbConnection>((sp) =>
{
var configuration = sp.GetRequiredService<IConfiguration>();
return new SqlConnection(configuration.GetConnectionString("Assets"));
});
What could be the reason for this error? Azure Function Core Tools runs the app in a container?
Run Azure Functions Core Tools:
$ func host start --pause-on-error
Run MSSQL in Docker:
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=P@ssw0rd" -p 1433:1433 -d mcr.microsoft.com/mssql/server:2022-latest
Error:
[2024-08-16T14:17:21.014Z] Function 'UpdateApplicationsManual', Invocation id 'ee6ddda8-cee2-4ba0-a461-510f31cfe65f': An exception was thrown by the invocation.
[2024-08-16T14:17:21.014Z] Result: Function 'UpdateApplicationsManual', Invocation id 'ee6ddda8-cee2-4ba0-a461-510f31cfe65f': An exception was thrown by the invocation.
[2024-08-16T14:17:21.014Z] Exception: System.AggregateException: One or more errors occurred. (A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 35 - An internal exception was caught))
[2024-08-16T14:17:21.014Z] ---> Microsoft.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 35 - An internal exception was caught)
1