How to connect Azure Web App to Azure SQL Database? - azure

I'm having what I hope is a simple problem.
I've published an API to an Azure Web App, which should fetch data from an Azure SQL database, but I'm getting a 500 error, which of course isn't helpful. Checking the logs in Azure doesn't give anything more useful to me.
I've added the connection string to the connection strings in the Web App. I have also created a method which returns the connection string from the repository class that's using it, so I know it's definitely seeing the correct connection string; so this means it's an issue connecting to the database with that connection string.
I have ensured that 'Allow access to Azure Services' is switched on, and when I use the query editor I can successfully pull data from the database.
I've also connected to the database using SQL management studio so I know the database can be reached.
What am I doing wrong?

As usual it turns out to be my stupidity, but I'll answer here in case it helps someone else...
I just updated my local app to use the Azure db connection string so I could get a more detailed error and it said the keyword was not supported 'initial catalog'.
This is when I realised that I developed this locally using Postgresql but couldn't justify the costs of that on Azure so switched to Sql Server but didn't change my connections to SqlConnection types!

Related

while I am connecting the my java application to azure sql database, I have to run the application twice

while I am connecting the my java application to azure sql database, I have to run the application twice .
1: while running the application I am able to create the database. it takes the database from the tenent.properties:-
devTest=DbName
database.properties file:-
jdbc:sqlserver://XXXXXserver2.database.windows.net:1433;user=XXXX#XXXXserver2;password={your_password_here};encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;
2: while running the application second time my connection ulr looks like below and I'm getting connected to the database which is mention in the connection string
tenant. properties:-
DevTest= DbName
database. properties file:-
jdbc:sqlserver://XXXXXserver2.database.windows.net:1433;database=DbName;user=XXXX#XXXXXserver2;password=your_password_here};encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;
Please help me out.
Advance thank you!!!!!!!!!!!!!
One of the workaround you can follow to resolve the above,
So basically you are not getting any error while connecting the azure sql database to java using JDBC driver for sql server . The difference only we can see is the db name is added after running twice.
Similar issue we had faced and after checking our internet connectivity and restarting the system able to connect when executing for the first time itself ,Suggest you to please try the same restart the application and system.
Few of the things need to ensure that you have added the following to your src/main/resources/application.properties
url=jdbc:sqlserver://$AZ_DATABASE_NAME.database.windows.net:1433;database=demo;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;
user=demo#$AZ_DATABASE_NAME
password=$AZ_SQL_SERVER_PASSWORD
The above provided information to be apply for the sql server which you have created earlier before creating the java project.
For complete setup please refer this MICROSOFT DOCUMENTATION| Use Java and JDBC with Azure SQL Database
For more information please refer this MICROSOFT DOCUMENTATION| How to connect to Azure SQL with JDBC

Azure Create SQL Database: Deployment validation failed

I am trying to create a free SQL Database in Azure under my DreamSpark subscription but I repeatedly receive the following error:
When you start an SQL Database creation, Azure lets you choose or create an SQL Server:
Since I don't currently have an Azure SQL Server I have to create one. I figured my error could be isolated to the server creation and effectively, while trying to create only the server, the error still rises.
I think that, even if Dreamspark subscription allows for a free small SQL Database, it does not allow for a free SQL Server. But this does not make any sense because I think there is no way to have an SQL Database without an SQL Server... So my questions:
Could you please confirm or refute my suspicion about Azure not permitting a free SQL Server in DreamSpark subscription?
In case it is not allowed, is there a way to create an SQL database without an SQL Server in Azure?
In case it is indeed allowed, why do I have this error then?
Thanks in advance.
I ended up circumventing this problem by using visual studio 2017 to create DB and DB Server for me. So we can be sure that DreamSpark subscription allows for a small DB AND a DB Server creation, which makes sense.
Still, don't know why I was getting that weird error though.
While creating the db, visual studio changed the name I provided by concatenating "dbserver" and "_db" to the server and db respectively. Perhaps, there was a naming issue that VS solved automatically, and that Azure is not reporting correctly.

Connecting Power BI to Azure SQL database without on-premises gateway running

I have recently started using MS Power BI, and have come across a problem which seems inconsistent, and the answer likewise.
I am connecting to an Azure SQL database, and therefore have chosen this as the data source in the desktop app. Everything seems to be working just fine, and I can create tables, graphs and whatnot. One thing is off, though: When I choose Azure SQL DB as the source, the connection dialog box does not appear to be any different than if I just choose (non-Azure) SQL DB. Puzzling.
The other thing, which is actually the main issue: In Power BI (the website), I can open my published reports, but some of them don't show up, and I get an error message in a pink bar at the top, saying the data source is not available because the gateway can't be reached. I am well aware of this, because I have deliberately stopped the gateway service (PBIEgwService) running locally, because I have read several places that if the data source is Azure, an on-premises gateway is not needed. (E.g.: "Question: Do I need a gateway for cloud data sources like Azure SQL Database?
Answer: No! The service will be able to connect to that data source without a gateway." here: https://learn.microsoft.com/en-us/power-bi/service-gateway-onprem-faq)
So in short: Why does PBI not (always) connect directly to Azure?
And yes, I have checked the credentials. I can connect just fine in PBI desktop.
Are you allowing Azure Services to connect in your Azure SQL firewall?
https://learn.microsoft.com/en-us/azure/sql-database/sql-database-firewall-configure#manage-server-level-ip-firewall-rules-using-the-azure-portal

can an Azure-hosted SQL Server connect with an Azure Cosmos DB?

Not sure if this is an option? Ideally looking at something like an openrowset query from a stored procedure within SQL server or a web job.
If so, are there any resources available to help learn how to make SQL Server and Cosmos play nicely together?
If your SQL Server in Azure is managed by you on a VM (IaaS) you should be able to add the Cosmos DB as "SQL Server Linked Server" e.g. by adding as ODBC Source.
Then it's also optional if you link the Cosmos DB PaaS service to your Vnet or access it via public endpoints.
Not 100% sure if this will also succeed with Azure managed instances (which is quite new in GA).

Replication sqlserver database to azure

Scenario: I have a server farm to deploy my web site. I want to try to add one server from Azure platform. Every host has a replication from one database server. I have tried to add the replication database but I got this message error:
Microsoft SQL Server Management Studio is unable to access replication
components because replication is not installed on this instance of
SQL Server. For information about installing replication, see the
topic Installing Replication in SQL Server Books Online. (New
Subscription Wizard)
After this message I suppose that something is missing in the sqlserver database Azure side.
I have googled something to solve my problem but without luck.
I have found one tool (Azure SQL Data Sync) and tried something to solve the problem but it didn't work.
From the Azure documentation, I have found that until V12 of the azure database replication wasn't available.
But what about v12?
Questions:Am I missing something with the version of the database? Should I change the database plan in Azure subscription?
Should I use some external tool that allow me to maintain sync my database server with the replication?
Replication is not yet available according to the MSDN even on V12. You can use https://azure.microsoft.com/en-us/documentation/articles/data-factory-introduction/ and https://azure.microsoft.com/en-us/documentation/articles/sql-database-get-started-sql-data-sync/. You can write your own sync logic with change tracking, Service broker and linked servers / safe CLR but better use the existing tools.
Maybe Azure Data Factory Service could be a solution for you?
https://azure.microsoft.com/en-us/documentation/articles/data-factory-introduction/

Resources