Easily Deploy a .NET 7 API to Azure! [2023 Tutorial]

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome in guys today we're going to go over how to easily deploy your.net 7 API to Azure as you can see we have an API open right here if we go to properties you're going to see that this is a Net 7 project right here if I run it you're going to see that we have a few endpoints and we have a working application we have a get teams a team by ID a post a put and a delete and this connects to a database that I will show you guys in a second but how do we actually start the process well we got to go to the Azure portal once we get to the Azure portal we need to make sure we have some sort of subscription whatever it may be then we're going to need to create a resource Group so we click here click the create button we're just going to call it rg1 doesn't matter what region and then just go ahead and review and create and go all the way through create it once it gets created we're going to continue and then once we have this now we can go and actually create our app service so once we're back at the home page and we've created our Resource Group now we can go to our app services and click create so once you're at the create web app page what you're going to want to do is select the resource Group you just created let's name this something let's create it demo API YT that's what we're going to do and it is available then we're going to be publishing code select the runtime step which is going to be dot net 7. it's going to be Windows whatever region you may want and then your plan your pricing plan all this you can set according to whatever you're working with for this demo I'm just going to go to free and then we're just going to review and create we don't need any of the other stuff and click create and we'll be right back once it's done so once you have your app service created you may think oh we can now go ahead and publish well not really because see our API is connected to some type of database if you go to our program it's using SQL Server so we're gonna have to actually migrate our SQL database and create an instance of SQL server in Azure so at our Azure app service actually has a database to work with which could be your production or whatever environment you want to create in Azure so with that being said we first before we can actually publish our API need our API to have something to actually get its information from so first let's go ahead and create our SQL Server instance and then let's grab our database and then put a copy of it up in Azure once you open whatever you use to manage your database in my case it's Microsoft SQL Server management Studio find your database in my case it's a sample database and if I open the tables you're gonna see that we have two we have a team table this is a project that was based on the World Cup so you had the countries that are participating with the Confederation they're from so this is you know this team table and if you go to a confederations table we're going to see that this is all we have here but now how do we actually get a copy of this database into Azure well the first step is to turn this into a backpack file and how do we do that so you're going to want to go ahead and right click the database name you're going to want to go to tasks and you're going to want to export a data tier application you're going to go here and you're going to want to save a copy somewhere locally on your machine so on your desktop I'm just going to want to throw it there we're going to have this backpack file and I'm going to call it sample database BP and then that's gonna actually be a backpack file with everything inside this database and it's going to be in this file we're then going to take this file and then we're going to go put that in Azure and that's how we're going to move our database without having to copy all our data move everything create our tables and columns this is how we're going to do that so click next and then it's going to go through and do this whole process and we'll be right back when it's done well we've finished exporting our database and turning it into a backpack file and we now have it right here now the next thing is we're going to need to create an instance of SQL server in Azure now that we have our backpack file the next thing that we need to do back at the Azure portal is we need to create an instance of SQL Server so find SQL server or search it up here if you want once you're here you're going to want to create one once you're at the page to create a SQL Server instance select the same Resource Group as before or whichever one you actually want then give it a name so I'm going to do demo SQL Server YT the location doesn't really matter and then we want to go down here to SQL authentication click that set your server admin login and password because you're going to need that in a second once you have all that correct then do review and create and then wait for this and create it and we'll be back when it's done once I've created the SQL Server instance I'm going to want to find the server name and I'm going to want to click copy the clipboard then I'm going to take it right back here and now I'm going to connect to it so we're going to click connect we're going to paste it in right here now we're going to switch to SQL Server authentication remember when we're creating it right now type in the username and password that you put whenever you're creating the SQL Server once we have it typed in Click connect it should ask you to sign in with Microsoft Azure so click sign in and go do that and once you've successfully signed in it may ask you to add a new firewall rule to allow your IP address to actually connect to Azure if this does not appear to you you can also set this in another place if you go back to Azure portal and you go here you should be able to go to networking and in networking you can add your IP address here as well so why is this helpful well once you actually create this database in Azure you may want to connect from your API and connect to that SQL database to make you know make sure that that works we're actually going to do that in a second but it will get blocked if you don't actually add it here or in this other instance like I'm showing you guys right here so click ok and over here on the left side you should see that your SQL Server instance starts to appear or wherever it may be now that we're here let's create our database in azure so what we're going to want to do is we're going to right-click databases we're going to import data to your application and we're going to want to find that backpack file so I selected that backpack file from my desktop and now we're going to click next just give it whatever default you want unless you already have some type of connection string and you want to call it the same thing you had before then go ahead and change the name of your database to whatever it was change whatever you want in here for your SQL database settings click next and then create it all right so once it finishes importing you should see your database appear here if you open it up it should contain all the data that was up here so if I right click team and I select the top thousand rows you should see that everything's already there I didn't have to copy anything over I didn't have to risk there'd be some data loss or anything like that I just moved this version over to here and now we have this and now let's go get this connection string so we can actually connect to it from our local API and then hit it in Azure to make sure that everything's working fine so now that we're back at our SQL Server instance we should be able to go to SQL databases and find the SQL database that we just imported click on it and then we're going to go down here to connection strings and we're going to use this connection string and put that in the app settings of our API and now that we're back at our API and we have that connection string copied I'm in my app settings we're going to go ahead and replace this connection string and then all you have to do is go in here and replace your password with the password that you inputted and now what we're going to do is we're actually going to test locally that our local API can talk to the Azure database so we can make sure that all the data is correctly there everything functions that we don't have to make any other changes so make sure that you have this connection string in here and if you actually scaffolded your database context using Entity framework there is some times that your database gets kind of put here and you don't want this to override the string in your app settings so just make sure this is deleted or whatever you want to do with it but once you have this then we can go ahead and test and if you're finding this video helpful please drop a like on this video so I can spread to other developers on YouTube thank you so now I'm just quickly going to test it I can actually talk to my Azure database we're going to just run this endpoint really fast we're going to do get teams let's try it out execute and we were able to get data how can we prove that I'm actually talking to this and not the local one well if we go back to our teams and I decide let's edit one of these rows what I'm going to do is I'm going to go in and I'm just going to slightly change the name of one of these countries we're just going to go in here and let's just add an X to France let's add three and let's close it that should save let's come back here and let's try this endpoint again let's clear it and execute and as you can see France so we are pulling from the Azure database now so now let's actually publish our.net 7 API to Azure so that it can now connect in Azure to everything in our SQL Server instance so now back at our app Services we click on the app service we created earlier going here we now want to download our publish profile this will contain everything our API and visual studio will need to actually publish to this space within Azure so let's download it now that we're back at our project what you're going to want to do is right click and then click publish and then when we're here you're going to click new and this is where we're going to import our publishing profile so we're going to click import profile then go find that publishing profile wherever it may be once you've found it you know when I click finish and it should get all the settings that were in that publishing profile so that then from visual studio all you're going to have to do is just click publish and it will just automatically publish to azure so now if you've confirmed that your connection string is correct and everything in there is fine and you have the correct connection string set and everything else is good all you're going to want to do is Click publish it will automatically open the project in azure so we see our projects open here but I don't know this doesn't feel right but let's test an endpoint anyway so we're going to do backslash API backslash API backslash teams and then backslash get teams because I believe that is the endpoint that we had here so it is a team it's actually team so let's do team and let's hit that end point so it appears that something's going on in the back that's not allowing this to actually work as you can see we're getting an air 500 so this is a perfect time to explain to you guys how do you actually kind of debug or find whatever air is going on once you push this to Azure because it's different right you can't just debug locally so let me find you where you can actually go and find the logs of whatever error might be going on so if you go back to your app service you're going to want to go to diagnose and solve problems from here you're going to want to go to application event logs you're going to click this and then this will fetch everything that's all the events that have happened in your app service then once you have these here you can click on it and it will show you the actual error so here you say some instance isn't supported but that's not actually the error the error is this one is it cannot open the server because I am basically not allowed I don't have access my IP address isn't allowed to hit my SQL Server instance because if you guys remember what we said was we allowed our SQL Server instance to hit our SQL database but we have not allowed our API to hit our SQL Server instance so we have to check that off and it's a very easy tiny little box that is kind of annoying if you don't know where it is but I've already kind of gone through it so you're gonna go to your SQL Server instance you're going to come down to networking click that here and then if you forget to scroll down right down here you want to allow Azure services and resources to access this server click save and it's almost like magic we're gonna go right back here and we're just gonna refresh this and boom we're actually getting if you remember France right here we're actually getting our end point we're getting our data our net API is actually in Azure with a SQL Server instance and then the same SQL database that we you know imported up there using that backpack file but that is also what you guys can do to actually debug and find areas it's kind of annoying and kind of frustrating but that is one place you guys can go to actually look at the logs and kind of see what is going on but with that being said guys if you want to learn how to create your own.net 7 API to be able to actually then push it to Azure using the knowledge from this video go ahead and watch this video right here
Info
Channel: Israel Quiroz
Views: 4,103
Rating: undefined out of 5
Keywords: deploying .net 7 api to azure, deploying angular app to azure, deploying angular app in azure, dotnet, azure, .net 7, deploying a .net api, how to deploy a .net 7 api to azure, Host .net api On Azure, Host .net Api On Azure 2023 Tutorial, Deploying .net 7 api To Azure 2023 Tutorial, deploy .net api to azure, .net api, .net, Deploying .Net 7 API To Azure, Host .Net API On Azure, Deploying A .Net 7 API To Azure, .net api to azure, .net 7 api to azure, deploy .net 7 api to azure
Id: EKqXAMLsnKQ
Channel Id: undefined
Length: 12min 15sec (735 seconds)
Published: Mon Dec 12 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.