This is a small VB.NET WebForms repro project, created for the purpose of reproducing the database connection error discussed in detail at StackOverflow.
The problem is that the application cannot connect to its supporting database. Failures occur, however, only when attempting to connect under these conditions:
- EntityFramework 6 DbContext
- Running under an Azure App Service
- Connecting to an Azure SQL instance
Other scenarios produce successful connections:
- [ADO.NET] [local website] [local database]
- [ADO.NET] [Azure App Service] [Azure SQL]
- [EntityFramework] [local website] [local database]
The stack trace for the System.Data.SqlClient.SqlException
indicates Named Pipes as
the protocol under which the application attempts to connect. Various reports indicate that
System.Data.SqlClient
falls back to Named Pipes after a failed TCP connection, assuming the
TCP protocol is specified in the connection string. In this case, both TCP and NP are failing;
neither attempt is logged by the Azure SQL Server.
To prepare for running this application, perform these steps:
- Create a new Azure Web App
- Download and import the WebDeploy publish settings into the project (you may wish to remove the current profile)
- Ensure the profile's configuration is set to
Release
- Using the Azure Portal (not SSMS), create a new empty Azure SQL database named
DbConnectionTest
- Copy the connection string to the clipboard for Step 4 below
To run this application, perform these steps:
- Show all files in the project
- Edit
Db\Utils.vb
to provide the datasource and credentials for the design-time connection string (the login must haveDbCreator
permissions) - Edit
Web.config
to provide the connection string for the local database - Edit
Web.release.config
to provide the connection string for the Azure SQL database
- In Visual Studio, press F5 to run the application
- Note that the TextArea control displays the name "Fred Flintstone"
- Using the publish profile you created earlier, publish the application to Azure
- Browse to the newly created website
- Note that the TextArea control displays:
- The connection string that was used for the connection attempt
- A report indicating that the ADO.NET connection was successful
- The EntityFramework connection error stack trace
The problem has been solved. For detailed information about the solution, see the answer at StackOverflow.