Can't interact with database when published to azure - sql

Below is the steps i have took to publish my Website to Azure. I have two data connections the "defaultconnection" for users tables log in register etc. The other is a connection to an Azure Sql Database.
On Azure i created a new app service.
In Visual Studio i click on project and select publish.
In the publish Web window that pops up i select Microsoft Azure Web Apps.
In the following window i select the app service i created in Azure.
In the settings window it shows the two connection database connections.
They both have the same connection string which is the Azure hosted Database. I am not sure what to change the connection string to for the users table. I created a SQL database in azure and connected that to the app service then used that connection string for the "defaultconnection". The string is below
Server=tcp:userauthen.database.windows.net,1433;Data Source=userauthen.database.windows.net;Initial Catalog=USERAUTH;Persist Security Info=False;User ID={your_username};Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;
I published to azure and am able to go through the pages but as soon as i try to interact with the database i get an internal server error 500.
I tried publishing the website without userlogin so i could see if it connected to the Azure sql database but i still get the internal server error 500. I am really stuck at this point and any assistance would be helpful.

So i changed the firewall settings to allow certain IP address and it worked. I can access both my databases.

Related

How to connect Azure SQL database to ASP.NET website hosted on a different server

I have created Sql database from Azure using my subscription. I copied the connection string supplied with my credentials correctly into my code and it work in visual studio but when I deployed to my hosting server for my website it displays connection error. I have set IP range to accept all IP yet not working.
By default, (when you create a new DB), Azure blocks ALL traffic to your database. In order to allow traffic to your database either you need to whitelist all the IP address or the best suggestion in your case is to enable 'Allow access to Azure Services' on the SQL Server settings. Find more details here

Azure App Services cannot connect to Azure SQL Database

I have an API published to Azure App Services, using ef core, connect to Azure SQL database. below are the steps and the problem:
The Azure SQL database is up and running OK, I setup two firewall rules, one for my local dev ip, one for Azure App. I can connect to Azure SQL from local without any issue, and I have done the migrations.
I copied the connection string from Azure SQL and put in the appsettings.json, running the API from my local and connect to Azure SQL without any issue.
I published my API to Azure App services without any issues, I can see my app running OK since it has static file.
Then I went to Azure App Services => Settings/Configuration => Connection strings, create one new connect string with the same key/value as I used in the appsettings.json, based on the document from Microsoft: https://learn.microsoft.com/en-us/azure/app-service/containers/configure-language-dotnetcore#access-environment-variables
But the problem is after I done these, my API still not working, the api call to SQL return error 500.
Anything I missed or did wrong?
Thanks!
Thanks for the comments CSharpRocks, I did by adding the client ip, but I figured that's not the right way, so resolved by set the "Allow Azure services and resources to access this server" to True, that works.
For Others looking for the answer I had followed the steps above and it still did not work for me. But when I went to Visual Studios --> Publish --> Service Dependency's --> Add Azure SQL Database That fixed it for me.

How to view data on the Azure SQL database

I created a default ASP.NET web form web site using Visual Studio. By default it contains a .mdf database file, Registration page, Login page and some other pages. Then I host this web application on Azure as a web app.
After that I did several registrations for the web site and I need to see the data (data which i used on registration) on the hosted application.
Is there any way to connect to the database file in Azure? In Azure, I did not set up a connection string. I just publish the app and it manages the database connection itself.
There is nothing inside the "Database" section
It seems that you do not publish your asp.net to Azure with Sql Database correctly. So, you could refer to this article to check if you have deploy database correctly.
As you have published, you could go to the database on Azure portal and choose query editor(preview). Click Login and enter the username and password you have set in Azure Sql server.
Also, you could open Microsoft SQL Server Management Studio to get your database. And you also need to login into the Sql Server as above.
After logining into the sql database, you will see all the data you have insert.
BTY, make sure you have synced the data in local database to Azure Sql Database. For more details, you could refer to this article.

Azure SQL database - login failed

I have two web apps in azure plus one SQL database. One of them connects to the db withouth any problem. However the other web app isn't able to connect. I get the error:
Login failed for user 'xxxxxx'.
This session has been assigned a tracing ID of 'a632c957-78dc-4f13-b07f-ff646b04895c'.
I already copied and pasted the connection string from the working web app to the other one with no luck.
Is there any configuration to maybe "allow connections" from a specific web app?
Thanks

Sql Exception when connecting to Azure Mobile Service database

I'm using .net backend for Azure mobile services. I've published the service on the cloud with the publishing profile downloaded from Azure portal.The service gets published successfully. But I'm unable to connect to the service with my windows phone client. I get 500 response from the service. The logs on the portal shows this error
"Exception=System.InvalidOperationException: This operation requires a connection to the 'master' database. Unable to create a connection to the 'master' database because the original database connection has been opened and credentials have been removed from the connection string. Supply an unopened connection. ---> System.Data.SqlClient.SqlException: Login failed for user 'KqRUJJyDGlLogin'."
I'm using web.config transforms and in the Web.Release.config , the connectionstring with name , "MS_TableConnectionString" is pointing to the cloud db.
Is something that I'm missing over here.
Please help.
Thanks
It seems to be a problem with droping and recreating the db.
If you have something like this:
public class MyInitializer: DropCreateDatabaseIfModelChanges<MyContex>
in your WebApiConfig.cs change it to CreateDatabaseIfNotExists...
If you want to change your model, manually drop the tables of your db.
That might not be a perfect solution, but it works for me.