Skip to content

Repository files navigation

ASP-Practice

Goals, Documentation and Issues faced:

Goals:

  • Study ASP.NET
  • Study HTML
  • Print information
  • Get information via text field
  • Print the text directly below
  • Study SQL and integrate new data from MS SQL server object explorer
  • Study dependency injection and what makes it work

Setup: Core ASP vs ASP.NET Framework and containers.

  • Ensure you're running a regular visual studio gitignore.
  • Here's what they don't tell you :)
    1. Core ASP is compatible with .NET 6+ while ASP.NET Framework is only compatible with 4.7 versions which is quite old. I personally chose to do a ASP.Net core web app simply because of that issue.
    2. Windows 11 users beware! For Razor pages, it MUST be ran using windows containers or else you will see issues within the page!!!
    3. Why though? Because Docker linux is compatible with Windows 11 Enterprise.
    4. Why do we care? If you're running a Docker Linux container, you cannot run the page with the data you've integrated via script, sql file, etc.
    5. How do we fix this? Don't use docker and ensure it's unchecked when you create the project. Run the default windows container and test the site via ctrl+F5.

Documentation (NOTE, this is going to match the guide):

  1. I followed the ASP.NET guide given by Microsoft. Link[https://learn.microsoft.com/en-us/aspnet/core/tutorials/razor-pages/razor-pages-start?view=aspnetcore-7.0&tabs=visual-studio]
  2. Added a data model in C# image
  3. I created a Razor page named Movies via add new scaffold item and ensured that the Model class and the database provider was accurate. image
  4. Updated the database via PMC within the NuGet Package Manager NOTE: DO NOT SKIP THIS STEP! image
  5. Created the property for the entity set (the database table)image
  • Now within the webbar, you have to type in the specific page name. Note: save yourself some trouble and use Edge or perhaps Chrome...Firefox cannot establish a connection...*
  • Feel free to create new pieces of data here. Additionally, you can edit the data via C# with the SeedData script mentioned within the MS tutorial.

Now here's where things got tricky. Issues mentioned here:

  1. Working with a database.
  • When you open SQL Server Object Explorer, you can see a bunch of files and stuff. Ensure you're looking at the correct database.
  • How? Print it to the console via C# script. image
  • I'm still confused as to what the name is. Where do I go to find it? You'll find it in the console.exe image image
  • Now you should be able to see your fields. Welcome to the beginning. What it opens by default is a T-SQL file based on your localdatabase. Lots more on this later.
  • Later has now arrived. Buckle your seatbelts because now it's time for the hard stuff.

Working with T-SQL

  1. Here's how you can pull up the screen.
  • Go to View > SQL Server Object Explorer.
  • Then view The local DB MSSQL in the SQL server via the name MSSQLLocalDb within databases, go to the proper database using the drop down button. image
  • Double click the table name with the icon and note the DB name (You'll need this later!!!) image
  • Boom, the screen shows as expected. image
  • Right click on the table name and select view data to see what's already in the Razor page. image
  • Then from here you can select the script button towards the top. image
  • From here you can insert more data. Feel free to take this further, I decided to download VS Code's extension: [https://learn.microsoft.com/en-us/sql/tools/visual-studio-code/sql-server-develop-use-vscode?view=sql-server-ver16]
  • From here you'll need to add a connection to a SQL server...this is where things get tricky too.
  • Select the plus to add a connection. Remember I said you'll need the DB name? Well now you do.
  • We're gonna use the host name and instance. You can find it here: image
  • Place that into the field and then press enter. Then press enter again for the next optional field and then select integrated image
  • This worked for me, results may very, but it will take a few tries to get this set up. Believe me it's worth the set up.
  • In VS Code, you can now see your database and add data via sql scripts and show the data. Be sure to utilize the USE statement to use your table.
  • Now you can use your MS SQL statements as such: image

Congrats, you've now integrated SQL within your ASP.NET project!

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages