-1

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?

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Mayuresh Jaiswal
  • 297
  • 3
  • 21
  • Configure the firewall to allow your connection attempts. Connection string is like any other; just put the ip/host, db name, user and password - connectionstrings.com. Get data out of the db using SQL, just like any other. StackOverflow is designed to help with specific problems, rather than to write a full tutorial for you in an answer. Please give a try at finding suitable tutorials yourself; there is no huge difference between your sql db being on azure vm vs local machine, other than firewall. – Caius Jard Mar 12 '20 at 10:48

1 Answers1

1

About connect to SQL Managed instance, it's located inside a Vnet.

The options to connect to it are :

  1. 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)
  2. 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.

Leon Yue
  • 15,693
  • 1
  • 11
  • 23