How To Deploy ASP.NET Application with Azure SQL Database on Microsoft Azure Cloud

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi guys welcome to digital Tech join so in this video we are going to learn about deploying your asp.net application that uses Microsoft SQL Server database and we are going to create some table and fashion record and then finally deploy that application on Azure Cloud platform now in my playlist on my channel that is a tutorial on Microsoft Azure you can see I created almost four videos now and the last video was about deploying asp.net application on Microsoft Azure Cloud but this was a very simple video where I for the beginners I created an MVC application and deployed on Azure platform but now today I am going to create an application I'll show you how to create a database connectivity and everything and fetch some record and then deploy this solution in Azure Cloud so this will have our MVC application and it will also have Azure SQL Server database so let's get started so this is the Azure portal that I've already logged in with my content is digital Tech joined gmail.com now here if you see right now I don't have any resources so the first step we are going to do is that we will create an app server uh that is uh app Services which is required to host our asp.net MVC application so let's click on this app services so this app service can be found in in the most used Services over here in the dashboard or else you can also access this from your left side menu you can search for app services or you can use your Global search bar and just type in app services so these are the methods where you can access your app service click on create app service so this is a free subscription and I have created a resource group called RG Trail now all these things what is Resource Group everything is covered in my previous videos I suggest that if you need any help in how to use Reserve portal then definitely go and watch those videos now this is the app server name this should be unique so I'm just typing digital Tech drawing app service yes it's stick that means it is available so this will be a global IP IP address or Global URL I'm keeping the runtime as dot Net 7 and then I'm keeping the region as East US you can also select a central India and South India and all these Provisions are there right now I'm just keeping the default East us and then this will be a free trial account and then I click on next so this is the GitHub which I right now don't need it so I click on networking and make sure that you enable Public Access and then finally click on monitoring so right now I don't want any application inside I click on tag and then I review it so here I click on create so while our if you go to your notification panel you can see it is creating this app service you can see deployment is in progress so this is the first step I've created an App service now let's go ahead and open Visual Studio and create a project which will use our database typing a visual studio 2022 and I just open it so now I create a project and I select asp.net MVC template which is right over here so click on next and I say azure DB hosting okay Azure app dbo stick okay so this is a name of the project click on next as dot in 7.0 as of now I'll just untick configure for https and I'll click on create so the project default project template is created and you can see our MVC project application is loaded and let's go ahead and quickly create the necessary requirement let's go first create a model class I select right click on the model say class and I see lead entity so this is a model that captures the leads so lead entity let's create the properties crop ID and then we have Source lead source it should also have crop date time lead date and this will be name of the customer and then mobile and finally email so this is a basic properties will Define okay this is set now property is ready just make will make sure that this ID is primary key now once we add the model ready let's go ahead and deploy the required manage tools so right click the project and select my nuget manager packet package manager and search for let's framework so we need Entity framework core and then we need our SQL Server since we are going to work with Microsoft SQL Server database Express Edition and then we need tools for using migration command Microsoft Entity framework core dot tools so guys there are a lot of videos in my channel which talks and explains about database connectivity and create screwed application so we'll not get into much detail we'll just quickly create this project so that we can main purpose is that we will need to deploy this on Azure that is the main goal so this tools are installed now let's go ahead and add our DB contest class right click the project say new folder and say data data right click say add class and say application DB contest now this will Implement leaving contest that's right DB contest right over here and then we are going to click on this and add the Constructor called with options we will also create a DB set from DB set and we'll use lead entity and we'll name this as leads so this is the name that we will be creating a table as leads so this is done now let's go ahead and open our SQL Server database Express Edition and in the meantime we'll go to our app setting and add the connection string over here so connection string names default connection and here I am going to copy the connection string which is already saved so this is the connection string so your database name I have not created so I'm just create this database name over here right click Azure DB okay this is the name of the database.db and I'm going to name that over here Azure DB so our database is there and everything our application DB contest is ready our model is ready let's go ahead and go to program files and add do add a dependency injection of the connection string Builder the services add DB contest and use our application DB class application TV contest class options this Lambda expression enter should not use SQL Server database like it and Builder Dot configuration.getconnectionstream and name of the connections now let's close everything and invoke our package manager nuclear package manager package manager console and say add migrations and this is our initial DB setup okay so it's not migrations migration and iPhone migration initial DB setup build started and succeeded you can see migration folders created and then let's update that update database so that the scripts run and the database is created in our database so you can see the script is running it's successful now if you go to Azure DB you see the table is created leads this is a lead table created and if you go to design the property that we defined as set over here ID leave date lead Source name mobile and email so our database ready now what what we'll do is we will use scaffolding and we will quickly create a model so for that let's right click on controller and say add controller and select MVC controller with use using Entity framework click on ADD so model name is lead entity which we created sorry lead entity TV contest is application which you created and that's it so it's scalp folding and it is generating the required code so we will be able to fetch the data create edit delete record everything so I use this method so that we can quickly get around this module and finally we will deployed on our SF platform with Ms SQL Server database so our model is ready Let's uh go ahead and check it so before that we'll just run the project and see the module so controller name is lead entities so just simply leave empty these here you can see our model is loaded so it has no records let's go ahead and select the date and select the lead source for website name John so so we are able to add the record and we are also able to update the record so this is our functionality is already there so now let's go ahead and add this lead entity Link in our home page go to the view here index no not shared sorry shared layout here you can see the ohm over here so control so let's say lead entities the controller name and action is index so action is index yeah so we have added the link so we can simply click on the link and display the records so click on home and you can see the lead module is displayed let's also change the name so go to Shared layout and it is on ohm it is crn leads okay CRM leads so guys our module is ready our our crude operation is ready now let's deploy this on Azure platform so what are the things we need to take care of so first of all in my Azure platform you can see my app service is now ready so this is my app service that is digital techzone app service which is ready now what I'm going to do is that go to visual studio right click on your project and say publish you need to select azure you need to select app service for Windows since I am doing it on Windows click on next I've already logged in with Mac on digital Tech joint which is same as this one over here and since I have already logged in it shows me the resources under the resource Group name and when I expand it I'll be able to see my service app service that is digital Tech join app service which is right over here okay I select that and I click on finish so it is creating the profile yes the profile is ready you can see it is actually created all the profiles now here what you need to do now since we have a dependency that is an SQL Server database over here we need to enable that over here so I what we will do is that we will this service is by default picked up so either we can edit it okay or we can ignore this profile because this is picked up by default and it as connection string which is pointing to our database okay so that is not what we wanted we want a database to be created over here in Azure platform and the application which is published on Azure should know that database is pointed to Cloud Azure platform not on my local system so what I'm going to do is that right click click on this dots over here and say ignore this profile okay so now I have ignore this profiles right now I need to manually add a dependency so what I'm going to do is just click on the plus sign over here and I'm going to select Azure sqls SQL database click on next now right now in my Azure platform in my under my account there is no Azure database SQL database created that is why it is not able to see any database over here so we can create a database from this platform from Visual Studio itself or you can go to Azure and also create from here as well okay so let's go ahead and let's create Azure SQL database from our visual studio so click on create new okay now here this is a database name so I am going to create the same name which I created over here so I'm going to say Azure DB but before that I need to create a database server right so here you can see database server and database administrator and password so before we specify the data this name let's click on database server new so I am keeping this database server as it is by default Azure DB hosting DB server default is East us I'm keeping it and I'm providing the administrator which I'm naming at digital Tech join admin and password is a capital admin123 dollar similarly admin one two three dollar so created this I'm clicking on ok now it is creating the database server it is already created it now I'll go ahead and change the database name to Azure DB which is same as created in my local database now once this is done I click on create now it's revalidating all the properties once and then it will create a database okay which will be also visible in my Azure portal now this takes some time it takes around 5 to sometimes 10 minutes so what are we going to do is we'll just pause this video and once it is created we'll resume it so guys the database is created so I can see in the list now the database name Azure DB and it is created in East Us location and this is a database server and now if I switch back to our portal and check whether the database is created you can see I'll just refresh it once and then I'm going to go to SQL databases now if you click on you can see the database is created over here and when you click on that you can see the various properties that we created is already there you can see the database server name and this will be the connection string so if you click on the connection string here is the connection string so what we're going to do is that we will also copy this connection string this will be required so this is the connection string that I am going to copy so I just copy the connection string over here and then we are ready now so our database is also set and it is can be seen over here now we'll go back to our Visual Studio and now I'm going to click on next so it's so this is the connection strings I am going to say default connection so remember in my app setting I had given a connection string name as default connection which is used in the program so that is reason again default connection and your database connection use your username okay so I need to give the database connection username I'll keep it as digital Tech join admin same as my database server and my database connection password will be admin a capital D m i n one two three dollar and this is the connection string if you see the connection string is already defined over here so I actually don't need to copy it from measure it is already picked up and then I click on next so it will install the necessary packages so I click on finish it is installing this packages and it will also do a connectivity test fine so this is done and I'll click on close now the most important thing to note over here is that we have created our app services that will host our website we have created an SQL database and database name is azure DB so but that database on Azure does not have the table that we created that is leads okay so in order to create a table what we are going to do is we are going to use our client that is Microsoft SQL server with my management Studio which is deployed in our localhost and we'll click on file and connect it and here we are going to connect other database that we created in Azure for that what we are going to do is that we'll go to SQL database click on our database name copy the server name which is right over here come to our client tool paste the server name over here select exclusive authentication and give the username that is digital texture and admin and password admin a Capital One Two Three Dollar let's try to connect now when I try to connect I am getting this error so before we host our website on Azure and try to use our database we need to make sure our database is getting connected via different lines so here you can see it is rejecting our connection to Azure database so in order to tackle this what you need to do is go to your Azure database that is on cloud click on Azure DB here on the top you can see set firewall click on that scroll below and here you can see firewall rules and here you can see add client so see this is the IP that I am trying to connect so I want to ensure that I give access to this client connecting to my Azure database that I created so just click on this add client you can see automatically it adds my IP addresses and click on Save it successfully added it now I go back to our visual studio console and try to connect back here you can see it is successfully connected okay so now our database is ready another and you can see it it is it has Azure database what we can do we go to our local database expand select our database Azure DB right click on our table script table as create copied in our clipboard come to our Azure database and here you can expand it and open the query window paste it over here and just execute this particular script which says create table leads and and make sure that I select azure DB of azure Cloud so that it executes over there or you can simply say use thank you the select database and save file connection current connection yeah now I think you should get executed select this it's got executed so our inner Cloud Azure server Azure DB right click on that refresh it once refresh it you can see it should you should see the table over here so our database now in Azure database as our table so right now go to visual studio now our profile is ready we have the app service ready it is already created the profile we have created a dependency of azure exclusive database and we have made sure the connection connectivity is there and we also make sure the data tables is created now simply we need to now publish it by clicking on this button so click on publish and here you can see it is publishing so Bill started publishing to Azure app service windows so you can check in the output Windows what is actually activities happening and the same is updated over here you see it's adding the directories it's adding the runtimes libraries so guys just have a note on this output window and make sure that you go through this once so you should be aware what all things are getting moved to azure Cloud platform the runtimes and services and here you can see the build is published successfully web app was successfully published now it is installing the esp.net core site extension you can see the update over here right in front of you in the profile window and it is loading this URL as well the website as well so this is digital interaction appservice.azurewebsite.net we should be able to see our site yes we are able to see a website on cloud now Azure we'll click on CRM leads and it should load without any issue because we also check the connectivity of database yes it successfully loaded it let's create one recorder on cloud we select the date select the leave from website name is John mobile is something and then John yahoo.com let's click on create button yes you can see the record is getting created and it's also getting deleted let's add one more record so we'll make some changes over here just to this is from social media and let's calculate gmail.com this is the second record we added it so everything is working we are able to successfully host our application that uses SQL Server database and we can see it is working perfectly fine what we'll do is that we'll edit it so we notice that when I create a record and click on leave date it is showing the time as well as date we don't want that also we don't want this label lead date and Lead source so what we'll do is we'll make a small change and republish our website so we go to our model class lead entity and here for date you see click type so this is a format that I gave and also our display name as date similarly for lead Source we say display name as source obviously with a space so this is a small change which we did we'll just rebuild a site it successfully now right click on that and say publish so this is a pop-up profile which is already ready we just have to click the button publish and it will publish back our changes to Azure portal this time the publish it should be fast because already published once as I told you it is quite fast this time and our site is ready it is loading so we'll be creating lead and this time we should be able to see the changes as well click or CRM leads we are able to see the two records correct which create a new lead now if you can see the labels have changed date and Lead Source now click on this button and here you can see only date calendars displayed are changes went very well heat source is marketing name is Rod number and here you go the changes reflected successfully so this is a small application that I demonstrated which you can use it and understand the steps in order to deploy your asp.net application that uses SQL Server database on Microsoft Azure Cloud platform so guys I hope you like this video please do subscribe my channel and share it with your friends family and colleagues to grow help me grow my network also do like and comment and also do let me know if you need any video related to asp.net or Azure or any other topic which you want me to cover I love to do it for you guys so thank you very much for your time and see you soon
Info
Channel: Digital TechJoint
Views: 20,660
Rating: undefined out of 5
Keywords: aspnet, msazure, clouddevelopment, webapp, microsoftazure, cloud hosting, azurewebapp, azuredeployment, aspnetcore, webdevelopment, cloudcomputing, azureservices, azuretutorial, visualstudio2022, appservices, saas, deploy web app on ms azure, azure free trial, MS Azure, asp.net deployment on MS Azure, ms azure cloud tutorial, courses, learning ms azure, ms azure certification, azure sql database, azure database, entity framework, working with azure sql database, asp.net with azure sql database
Id: jT8eA9A7qXE
Channel Id: undefined
Length: 30min 22sec (1822 seconds)
Published: Sat Jun 03 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.