ASP.NET MVC website for Mobile using Oracle DB
August 30, 2011 3 Comments
This application provides a live demo of developing an asp.net mvc 2 web application using Oracle 11g as backend. The prerequisites of the lab is:
1. Microsoft Visual Studio 2010 (Ultimate, Premium, Professional) with .NET Framework 4.0
2. Microsoft Visual Studio 2008 (with MVC 2.0,3,0 plugins installed).
3. Oracle Data Provier (ODP.Net) for Visual Studio supporting entity Framework with Linq. Download here: http://www.oracle.com/technetwork/topics/dotnet/downloads/odacefbetainstallinstructions-302527.html
4. Oracle 11g.
5. Windows Phone 7 SDK , Opera Mobile Browser 11.e
The MVC application is build with Model, View , Controller infrastructure in ASP.Net Applications. Controllers present the code – behind logic like asp.net webforms where as view represents the UI layer. The model encapsulates the business logic & data embedded within the database.
- To start the application click on visual studio File -> New -> Project – > Web.
- Select ASP.NET MVC 2 website & select a name of your application.
- Click on finish after providing Solution name, location.
- Connect to Oracle database by providing the user name & password . To implement it click on view -> Server Explorer->Check the ODP.NET Add Connection.(Please note : if you have installed Oracle Data Provider for Visual studio for EF & Linq, it will open the ODP.Net Add connection property on clicking add connection property )
- Select the DataSource Name . (Please Note: in case of Oracle local database provider residing on same computer , you can select ‘(Local Database)’ otherwise for remote database Select your data source name updated in ‘tnsnames.ora’ file.
- Provide the user name & password & click on test connection button. If it connects successfully then the database will open in Server Explorer.
- I have created the user ‘Scott’ in Oracle (Local Database) so I opened the tables of Scott user in Oracle. There are some in built tables in Scott users like EMP, DEPT. For this application I have used only the EMP table.
- Right -Click on EMP table & select ‘Query Window’. write the following query in window.
Select* from EMP;
Check the output of the query.
- Start the ASP.NET MVC Project in Visual Studio.
- Right-Click on Model folder & select ADO.NET Entity Model Framework.
- Provide a suitable name for the .edmx file. For this project I have provided Employees.edmx.
- Select the option ‘Select from Database’ Click on Next, Select the ‘Data Connection name’ in this case ‘SCOTT(Local Database)’ & check the radiobutton ‘yes , include sensitive information in connection string’ & check the connection string name in application configuration file.
- Click on next & select the Model name & provide a suitable model name & select the table, View, Stored Procedure & click on finish.
- The .edmx file will create the employees.edmx with datacontext backend files.
- Right Click on Controller folder select new Controller & provide a name ‘IndexController’ & click on Checkbox ‘Insert, Update, Details’.
- Click ok & check the Index Controller.cs file.
- Open the IndexController.cs file & modify it by just mentioning Index() method & creating a object of SCOTTEntities class. Comment out the rest of the code.
- Build the solution first then right click on Index() method & select Add View to add a new Index view of the application.
- Provide a name of the view as Index & select the checkbox ‘Create strongly typed view’ & View type select ‘details’.
- Click finish. The index view will create the normal view with HTML codes.
- Now click on ‘start Debugging’ or F5 to launch the application.
- check the output in Opera Mobile emulator on ‘Samsung Galaxy Tab’ view or Windows Phone emulator.
Now the website is ready….