1

I'm trying to connect my Azure Web App to my AzureSQL database.

In the Kudu Env (https://{my-app-name}.scm.azurewebsites.net/env) there is some kind of default connection string:

 LocalSqlServer
 - ConnectionString = data source=.\SQLEXPRESS;Integrated
   Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true
 -  ProviderName = System.Data.SqlClient

I have set the connection string in the App configuration, it looks like this:

Data Source=tcp:myapp.database.windows.net,1433;Initial Catalog=databaseName;User ID=databaseSA;Password=password;

enter image description here

But no matter what I try, the connection string in the Kudu environment never changes. This connection string is also set no where by me, neither in the code base nor in any Azure settings I found.

It's very similar to this SO, which never got resolved: Azure Web App Not Showing Connectionstring in Kudu Env

This is the error message that throws when the app tries to access the database, which makes sense since the connection string tries to connect to .\SQLEXPRESS which doesn't exist anywhere (locally I use .\SQL2019 as connection string): enter image description here

I would appreciate any help or hint.

kirbby
  • 226
  • 3
  • 8
  • Please refer [error 25 - connection string is not valid](https://www.sqlservercentral.com/forums/topic/sql-network-interfaces-error-25-connection-string-is-not-valid) and [SO Thread](https://stackoverflow.com/questions/49147124/invalid-connection-string-when-connecting-to-sql-server-express) – Harshitha Veeramalla Dec 31 '21 at 09:40
  • Thanks for your answer, But I know that the connection string is wrong. I need help in finding where to change it in Azure. I don't want to connect to SQLExpress but to AzureSQL. The SQLExpress is some kind of default in Azure. I edited above and included the desired connection string. – kirbby Dec 31 '21 at 10:25
  • Have a look at [Azure Web App: Connection Strings](https://build5nines.com/azure-web-app-connection-strings/#:~:text=Navigate%20to%20the%20Azure%20App%20Service%20Web%20App,used%20to%20manage%20the%20settings%20for%20the%20application.) – Harshitha Veeramalla Dec 31 '21 at 10:53
  • I don't wanna be rude but did you read my question at all? I set the connection string there but it does not change anything. Also in the linked SO thread the same problem exists. I also tried deleting the connection string in Azure and setting it in the .Net code directly, that also did nothing to change the .\SQLExpress connection string. – kirbby Jan 01 '22 at 00:26
  • 1
    Hello @kirbby, Could you please refer this SO THREAD :https://stackoverflow.com/questions/36826186/azure-web-app-cant-access-azure-db?rq=1 , May it helps.! – AjayKumarGhose Jan 03 '22 at 06:18
  • Thanks, this didn't directly helped me and I had already checked this thread out prior. But it kinda forced me to go over all the names and settings in code again and now I figured it out. – kirbby Jan 03 '22 at 09:21

1 Answers1

0

So after 3 days I finally managed to get it to work.

First I got it running locally, be sure to white list your IP in the Azure database firewall settings. Then I got it running in Azure and checking all the names and settings again.

I used the first connection string from my Azure database (SQL Authentication) with the database SA user. I set that connection string in the connection string of the Azure Web App.

Also make sure that the connection string in your code is the same as the one in the Azure Web app configuration.

Also during some point my App didn't run anymore due to errors in the .Net code, so beware of that.

I thought I had tried this already before posting here, but I guess there were some wrong settings in all these tests.

kirbby
  • 226
  • 3
  • 8