1

I have been using local databases to develop web applications in ASP.NET Razor Pages. My experience was that the local database creates itself simultaneously with the development of the web application.

Currently, I need to work with a cloud database set up in Microsoft Azure. This cloud database already contains tables. How can I connect to the cloud database and call these tables and their attributes in razor pages?

doodsy
  • 27
  • 3
  • The fact that you are using Razor Pages as the UI layer shouldn't really matter for the data layer. You'd need to change your database connection string usually. Are you using Entity Framework Core? – juunas Jun 09 '20 at 05:44
  • I'm not too experienced using ASP.NET too. What is Entity Framework Core? – doodsy Jun 09 '20 at 05:49
  • It is a very common library used for accessing databases. – juunas Jun 09 '20 at 05:56
  • Hey @doodsy, do you have the connectionString in the Startup.cs file or in the DbContext file ? can you please share the code where you retrieve so that we can help you? Here you can read about Entity framework Core https://learn.microsoft.com/en-us/ef/core/ – Mohamed Sahbi Jun 09 '20 at 09:43
  • Hello, I've been working on the web application with the local database (connection string in appsettings.json). I was actually thinking if I could just publish this web application to Azure and this local database with it. Would that be a possible solution? – doodsy Jun 09 '20 at 10:11
  • If you need further help, please tell me.And I am happy to help. – Jason Pan Jun 11 '20 at 01:14

1 Answers1

1

You need read the offical document first.

There are two ways you can set your sqldb connections. One is written in the appsetting.json file, and the other is set in the portal, as mentioned in the official documentation.

The difference between the two is that the setting priority in the portal is higher than the configuration in the code file, and the configuration will be overwritten when it is released.

For novices, you can get the Connection strings in the portal. Then you first ensure that your program can run normally, and replace the connection string in the appsetting.json file with the string provided in the portal. If normal CURD operation is possible, then the connection is successful.

Jason Pan
  • 15,263
  • 1
  • 14
  • 29