Translate

How to Run the Scripts in MVC ASP.NET MVC 4 Web Application?

1. Open Visual Studio (if it is not already open).

2. Open the ASP.NET MVC 4 application you just created (if it is not already open) by selecting the menu File ➤ Open Project and then browse for the folder where the
application is. Figure 1 shows the open application.



Figure 1. Application opened in Visual Studio 2012

3. Run the application by pressing F5 or by choosing Debug ➤ Start Debugging (Figure 2).



 Figure 2. Start Debugging option in the Debug menu

4. On the application home page that opens, click the “Log in” link in the top-right corner of the page, as shown in Figure 3. As described earlier in the chapter, we are trying to execute a user account operation with the AccountController class. The operation will open the login page to authenticate users, but first the AccountController class must determine if the supporting database and tables are ready to handle such operations; if they are not, ASP.NET will create the database and tables, which will take a minute or less depending on your machine.



Figure 3. “Log in” link on the application home page

The login page appears, as shown in Figure 4.



Figure 4. Login page

5. Once you reach the login page, close the web browser and then click the “Stop Debugging” button in Visual Studio, as shown in Figure 5. This has effectively created a LocalDB database and populated the tables for the initial configuration of SimpleMembership.



Figure 5. Stop Debugging button in the toolbar

6. To work with the database, in the Solution Explorer window, click the HaveYouSeenMe project (not the Tests project) to select it, and then click the “Show All Files” button, as shown in Figure 6. Clicking the Show All Files button displays all files in the project folders whether they are a part of the project or not (including those folders and files that are normally hidden in Solution Explorer). Then, expand the App_Data folder and you will see the LocalDB database file.



Figure 6. Finding the LocalDB database file in the Solution Explorer window

 7. Right-click the LocalDB database file and select the option “Include in Project.” This step is not required, but it saves you time and effort in the future by making the file available for editing without having to use the Show All Files button every time.

8. Double-click the LocalDB database file. This opens the Server Explorer window (which
allows you to open data connections and to log on to servers and explore their databases
and system services) with the contents of the LocalDB database file displayed. Expand
the DefaultConnection node and then the Tables node, as shown in Figure 7. The
DefaultConnection node represents the connection to the LocalDB database file as
defined in the Web.Config file in the root of the application. The connection configuration
provides the application with the information to locate and connect to the database. Note
that the tables have been created in the database file.

 

 Figure 7. Server Explorer window displaying the contents of the LocalDB database file

9. To execute the database scripts, right-click the Tables node and select “New Query,” as shown in Figure 8.





 Figure 8. Opening a new query window

10. Copy the queries into the query window and click the “Execute” button, as shown in Figure 9.


 Figure 9. Executing the scripts in the query window

The results window should display a message indicating successful execution, as shown in Figure10.



Figure 10. Query execution results window

11. In the Tables node in the Server Explorer window, right-click the Tables node and select “Refresh.” You will see that the new tables are now created in the database. Expand the Pet table, for example, and you will see all the columns of the table, as shown in Figure 11.



 Figure 11. Server Explorer window displaying the new tables and the columns of the table Pet




No comments:

Post a Comment