Connect to SQL DB of Azure VM using c# - c#

I have an Azure VM and a SQL DB on that VM - IAAS.
I want to get data from that DB using C#, but I'm unable to get how to connect to SQL of Azure VM using C#.
Any suggestions?
What would be the connection string I have to pass, and how can I get data from that SQL on Azure VM?

About connect to SQL Managed instance, it's located inside a Vnet.
The options to connect to it are :
From the Azure
Inside the same VNet (different subnet)
From different VNet using VNet peering / Site-to-Site VPN / Express
Route circuit (for cross-region connection)
From on-premises .
Using express Route or VPN
Then you can learn from this document:
Connect your application to Azure SQL Database managed instance:
You may choose to host application in the cloud either by using Azure App Service or some of Azure's virtual network (VNet) integrated options like Azure App Service Environment, Virtual Machine, Virtual Machine Scale Set. You could also take hybrid cloud approach and keep your applications on-premises.
Whatever choice you made, you can connect it to a Managed Instance.
After you configured these settings, you can reference Quickstart: Use .NET and C# in Visual Studio to connect to and query an Azure SQL database. This tutorial also include the Managed instance.
Hope this helps.

Related

SQL Server connection through Azure Hybrid Connection?

The end goal of this is to be able to expose a on-prem SQL Server so that it can be connected to like a 'regular' SQL Server using Azure. I'm trying to avoid doing a Azure Data Sync as I don't want to 'copy' data in this situation, although I will probably have to fall back to that if this doesn't work out.
So far, I've created an Azure Hybrid Connection to the SQL Server and now I'm trying to connect to the SQL Server through the Hybrid Connection.
I've managed to connect to the Hybrid Connection by creating an SAS token and connecting. However, now, I'm thoroughly stumped on how to pass a connection through that connection if that makes any sense.
I've tried using Stream classes but those don't seem to fit what I want to do in this situation. I'm having trouble googling or searching on StackOverflow because of how convoluted this whole thing is.
Is this even possible? Is there some class or library that I'm missing here?
According to your description, you could follow the steps below:
1) Create Hybrid Connections via your App Service app in Azure Portal, details you could follow Add and Create Hybrid Connections in your app.
2) Go to "Networking > Configure your Hybrid Connection endpoints" of your App Service app, then click Download connection manager or HybridConnectionManager.msi for downloading the Hybrid Connection Manager. You could sign in with your Azure account, choose your subscription, select the hybrid connections that you want the HCM to relay or you could select enter manually int the HCM with the Hybrid connection string from Azure Portal. Details you could follow Hybrid Connection Manager.
Moreover, you could follow Accessing on Premise SQL Server Database From Azure Web App Using Azure Hybrid Connection, though it uses the older BizTalk Hybrid Connections.

Windows programming service is unable to connect to Mysql database

I am using a windows programming in c#,the windows service which I am using as to connect mysql database to fetch the data and it has to upload the data to server.But when the services is being started in my local system, the windows service is getting started first and then Mysql database service is getting started.
In this case, it is unable to connect to mysql database, so that I have to create a dependency that mysql should start first and then windows service has to start next.
How to implement the dependency code in my program,such that the clients who are using this windows service should not effect with this problem,I have do it through code that it has to be done automatically.
You can set DelayedAutoStart = true for you System.ServiceProcess.ServiceInstaller in your Installer class.

How can I upload a local DB to Windows Azure?

I develop a WebApi using a LocalDB, but I want to deploy it to Azure. I found out that you cant use a LocalDB, but you can use a SQL Server Compact.
Is there a way to migrate my old database including the EDMX and all the models to the SQL Server Compact or is there any other approach to upload the application to Azure?
Do the same, but for MSQL, and after use your Microsoft SQL Server Management Studio for your TSQL deployment on SQL Azure.
I found out that you cant use a LocalDB
We can connect to on-premises SQL Server from a WebApp in the Azure App Service using Hybrid connections. There are some snippet from the document. More detail info please refer to tutorial.
Hybrid Connections can connect Azure App Service Web Apps to on-premises resources that use a static TCP port. Supported resources include Microsoft SQL Server, MySQL, HTTP Web APIs, App Service, and most custom Web Services.
As matze supplied link mentioned, we also can publish database to SQL Azure.

SQL notification problems upon Change from local IIS to azure APP

I am trying to upgrade my application from being in a local machine (both application and SQL server) to using the combination of Azure APP and Azure SQL service. I have successfully published the code in the Azure Web App, and the Application works except from one error that keeps on comming.
"{serviceResponse:{success:false,message:"System.InvalidOperationException: When using SqlDependency without providing an options value, SqlDependency.Start() must be called prior to execution of a command added to the SqlDependency instance."
in the Application start I am indeed using the SqlDependency that works only locally. The only sort of solution I found is to use the SqlNotificationRequest, but I have not been able to make it work using it.
What corrections do I need to do in order to make the App work with my remote DB? I am using C# (.net) and SQL server 2016.

How to allow client IP access to Microsoft Azure database?

I am developing an Android App. When my App starts this error in below screen shot appears
I added a new rule on my server in the Azure portal to allow access for the client IP in error message, but I still have the same error. When I am Trying to execute sp_set_firewall_rule I have this:
I'm using a web service to connect my android App to microsoft SQL server database on Azure.
As #DavidMakogon said, please check the firewall of your Azure SQL Database whether allow access to Azure Service if your web service had been deployed on Azure, please see the figures below.
Fig 1. Browse the overview tab of your SQL Azure on portal
Fig 2. Enable the option for Allow access to Azure Service to ON
Then all of your web services on Azure can access the SQL Database.
Or if your web service had been deployed on other platform for accessing the SQL Database, you need to click Add client IP, then the Client IP address will be added to the firewall whitelist as the figure below.

Categories