Http Request from Azure SQL Stored Procedure (no CLR) - sql-server

I'm moving an on-premise SQL Server database to Azure SQL Database.
From inside a stored procedure, we need to make HTTP request.
I had built a CLR assembly to make HTTP request, and all was working well.
From what I understand, CLR Assemblies are not supported by Azure SQL Database.
So I have to find an alternative,
Note that the use of stored procedure is for a legacy app to communicate with our app.
The legacy app cannot make an HTTP request (or the devs don't know how).
So basically it goes like:
Legacy App --> Our Stored Proc --> Our Web App.
I'm looking for the simplest solution for an Azure SQL Database stored procedure to make a call to a Web App.
I would prefer no polling solution, ie: Legacy App insert row, then our Web App pools the database.

Related

Null Reference Duende Identity Server on Web Assembly publish to Azure

I have a very simple Web Assembly application that is simply testing out publishing to Azure with Duende Identity Server with a SQL Server operational data store. The "functionality" is limited to displaying data from a single table.
This is running correctly in a development environment when connected to a local SQL Server for both the operational store and the functional data base.
I have deployed the database to Asure, and the application also functions correctly when I switch the connection string from the local database to the Azure SQL.
However, when I publish my test application to Azure Application Services, I get a 500 error and the message:
This page isn’t working right now
I have looked at application Insights and see several null reference exceptions:
Microsoft.AspNetCore.ApiAuthorization.IdentityServer.IdentityServerJwtBearerOptionsConfiguration+d__5.MoveNext
and three exceptions similar on:
Duende.IdentityServer.Hosting.DynamicProviders.DynamicSchemeAuthenticationMiddleware+d__3.MoveNext

How fetch data from Azure SQL via Xamarin App? Tutorial

I am creating simple application where I need get and fetch data to DB. As I find out from Xamarin app is standard using of HTTP request to DB instead of directly connect to DB.
I create Azure SQL DB, I create application with connection to this DB. But I cant really find out how it now should works.
There is no many tutorials or they are not fully described.
I read this one https://learn.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-xamarin-forms-get-started#download-and-run-the-xamarinforms-solution
I find many references on this one but it seems out of date. Everybody recommended download the project from section
Run the Xamarin.Forms solution
On the settings blade for your Mobile App, click Quickstart (under Deployment) > Xamarin.Forms. Under step 3, click Create a new app if it's not already selected. Next click the Download button.
Under this tab I have only references to next tutorials but not any to Project Download. (screenshot below)
https://imgur.com/THCdUE1
Can you give me some advice if I do something wrong? Or link to updated tutorials? I am little desperate from this
Many Thanks
Azure SQL is not an HTTP/s service-- it runs proprietary SQL Server protocol on port 1433, just like on-premise versions of SQL Server.
If you are trying to connect directly to SQL Server from a Xamarin App, you are almost certainly making a mistake. Doing so would require providing credentials to your Xamarin app that can connect directly to your database, which opens your database up for a malicious user to do pretty much whatever they want to. The reason this kind of 2-tier application is dangerous is because the Xamarin app runs on an untrusted device (your user's mobile device), and a malicious user can intercept any data that your application has in memory, including your database credentials. They can then use those credentials to gain access to your database. Unless you were to use unique database credentials for each user (very impractical) and setup very stringent security roles in SQL Server, it'd be impossible to keep a malicious user from accessing the database for all of your other users (which is very, very bad). The other problem is that many networks block traffic on port 1433, or only allow access via an HTTPS proxy server, so your application would not function on many networks if it tried to connect directly to SQL.
This is the answer to your question, but please don't do this:
If you are certain that you have taken care of the security correctly, you should be able to install the System.Data.SqlClient nuget package and use that to communicate with SQL Server as you would with any .NET application. Here's a code example from Microsoft.
This is my opinion on what you should do instead:
The correct way for most Xamarin applications to communicate with Azure SQL database would be via an intermediary application server.
If your application access data specific to a user, should have per-user credentials in it (username and password that get exchanged for an authorization token when the user logs in is a common technique). The Xamarin app would then use HTTPS to make requests to your application server using those user credentials. The application server would validate the user credentials (authenticate that they are legitimate and authorize the data being requested based on who the user is) and make requests to Azure SQL.
If your application only access public data anonymously, then you can make unauthenticated requests to your application server which will blindly request that data from Azure SQL and return it to your client (though it would also return the same data to any attacker on the internet, so be sure if you use this approach you intend all data served to be public to the world).
In both cases, your application server would be the only piece that communicates with Azure SQL. For a .NET application this would typically be done via System.Data.SqlClient or perhaps indirectly through an ORM like Entity Framreworks. The advantage to this 3-tier approach is that the untrusted client tier does not have unrestricted access to your database tier. Only the middle application server tier has the credentials for SQL Server, and it is trusted and runs in a secure environment (a server you manage, not an end-user's mobile device). This means that an attacker cannot intercept the database credentials and misuse them. It also means that your application only requires HTTPS data access to function, so your application will work on almost any network.
This is probably not the answer you are looking for, since it involves authoring an entire application server that has to be hosted by you (Azure App Service would be my recommendation, if you are already using Azure SQL). It also requires you to implement an API on the server, and then write an API client for your Xamarin application. This is no small amount of work.

How can I use a Azure Database for PostgreSQL in a Azure Logic App?

To simulate a device I want to use a Logic App to fill a Azure Database for PostgreSQL with test data.
I found the two connectors PostgreSQL and SQL server but unfortunately both don't work for me. The PostgreSQL connector does only support onpremise databases and neither the autodetection nor the manually input of the connectionstring works with SQL Server.
Would great if somebody could give me a hint how to write data into a Azure Database for PostgreSQL from a Logic app.
Unfortunately, there is no connector available for this as of today.
The current alternatives would be
Use Azure Functions (which can be called from Logic Apps if required)
Create Custom APIs and a Custom Logic App Connector
Also, there is a feature request on UserVoice that you may upvote to gain traction.

Call Web Api json webservice from SQL Server stored procedure

I am trying to find a way to call a web api web service that returns json from a SQL Server stored procedure. I have found ways to call SOAP web services but not web services that return json.
Also the web service requires authentication with username and passwd.
Any ideas?
You can use CLR (Common Language Runtime) SQL Server objects which enables programming in .NET within SQL Server
I used once created and used a CLR split function in SQL Server

Database procedures and functions vs web services

In our development team we have:
4 developers
one application uses PHP and database Microsoft SQL Server 2008r2, except one using PowerBuilder instead of PHP and one using MySql instead of Microsoft SQL Server
All applications are database-centered, some of them are for general public, some are not.
Question is: for the procedures and functions shared by all applications, what does it make most sense to use, database procedures/functions or web services?
We could not find an agreement within the team.
Whatever you answer, please explain the reasons.
Webservices and Database Proc/Functions are two entirely different things.
Webservices are the services over the web, mainly used when a client and a server interact and client interacts with the server through web or HTTP or any other protocol.
Database proc/func - are created to interact with a login to a DB server.
In your case, if all the application are in the same domain... then you dont need to access through webservices and also it is a lot of overhead.
You can create a common DB server , where you can keep these proc/func and can be consumed by all.

Resources