asp.net mvc example with db - asp.net

I know the basics of MVC. But I am looking for an asp.net mvc example with db.
The following example explains the same - but the db is within the app_data folder. But in real practice, as u know, we will use an external SQL server for this
http://www.asp.net/mvc/tutorials/older-versions/movie-database/create-a-movie-database-application-in-15-minutes-with-asp-net-mvc-cs
Can u pl site an example - which explains asp.net mvc with db (just save & retrieve)

It might not completely meet your question but it is quit usual to use Entity Framework or NHibernate to manage your database
See ASP.Net site or the Entity Framework tutorial
Maybe you can find some other answers at that site.

There is no difference on the mvc side. You just have a different connection string to point to a sql server instead of a file inside app_data folder.
Create the same database on you local sql server express and change the connection string to point there. You'll see that will work the same.
In order to make your life easier, you can download SQL ServerManagement Studio Express (this is 2008 version)

Related

Connect Azure database to existing Asp.Net web application

I'm actually working on an university project and have to figure out how to connect my windows azure database to an already existing ASP.net web application project.
The web application should run on smartphones and tablets.
Since this is a group project, we use TFVC to manage the project.
Our client supplied an mysql script that will create the tables needed.
The Database is hosted in Azure and we want to access it through Visual Studio ultimate, so we can reveice data from the DB and integrate it's data in the application.
I also got the connection string, so I could use it if needed.
So my question is:
How can I connect to the database through visual studio and afterwards: how can I access to it? With access I mean, how and where can I use SQL queries in Visual Studio?
I don't really know where to start, whether it is connecting to the DB via code or on another way.
Every kind of help is welcome.
Thank you in advance.
Your question is still quite vague on specifics of what you want to achieve but hopefully this answers it. If not, please provide even more detail on your question.
If you just want to see the DB in Visual Studio and interact with it
Download the Azure SDK
Go to Tools > Connect To Database
A side box will open and you can navigation through Azure then to your database.
Personally I prefer using SQL Server Management Studio, its much more responsive that the UI through Visual Studio.
If you want to connect your application to Azure, as in code an application that talks to a database, then you just need to replace the connection string in your Web.Config to your Azure Connection String. Then either use ADO.NET, Entity Framework or another ORM.
I recommend Entity Framework but it all depends on what your circumstances and project requirements are.
If the DB already has its schema defined get started here:
https://www.asp.net/mvc/overview/getting-started/database-first-development/setting-up-database
If its empty you can use code first:
http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application

How can I obfuscate database authentication info during open-source development?

I'm working on an open-source web application that will retrieve and display data from a database whose authentication info I would like to keep under wraps, but at the same time, I would like anyone to be able to view and contribute to the source code. The idea is that we don't want the database to be used for profit.
Is there a way to make the database schema public, but only have a few rows of each table actually visible outside of the production server? I'm using ASP.NET MVC 4 in Visual Studio 2012, hosting the code on git, and publishing to Windows Azure. I'm also using a pre-existing Microsoft Access 2007 database.
You could encrypt the connectionStrings section of the Web.config file.
How you do that is described here. The connectionStrings section would not be decryptable on any machine except the server. It would be rather inconvenient for other developers though. You could set up so that this connection string is only used when the web site is published using transforms.

Securing an asp.net 4.0 website with forms authentication, with user credentials on a remote SQL server

This is my first foray into building a secure web application. It will be on the internet, and it comprises an IIS server (hosted by ISP) and SQL 2008 db (Also hosted by ISP.
As a quick and dirty test I am just using the template in Visual Studio. I have configured authentication by just using the wizard on the ASP.NET configuration tool. However, this creates a database that is hidden within the web app.
I would prefer to keep the user credentials on the SQL server, as it seems like best practice to allow for scalability. However, how do I do this? I have limited access to the database - I can create tables, but don't think I'll be able to run any tools on the server to create the right schema. Can anyone point me in the right direction? Done some googling, but keep seeing ASP.NET 1.1 articles, which makes me think I may be missing something, and there is a better way of doing this in ASP.NET 4.0.
Create a User table in SQL Server that stores user login and password. You can hash the password so that it's not visible even to admins themselves including yourself. Then using LINQ to pull during form authentication to check login name/password against the User table.
You can also use embedded SQL or stored procedure in place of LINQ. However, embdedded SQL is highly unsafe so that leaves stored procedure and Linq. I would prefer using Linq if you are familiar with it. Or using stored procedure which is always the safest.
You don't "have to" use the entire ASP.Net Membership framework to use Forms Authentication. It does a lot of the plumbing for you (security, etc), so if you can, it's probably best you use it - more so, if you're getting started.
You can use Forms Authentication with any auth scheme you want (pre-existing or something you create yourself). Here's an overly simplistic sample where you can see that you can even hard-code the auth scheme (not that you should, but it shows you the possibilities).
Lastly, if you can't run the command line ASP.Net tool aspnet_regsql.exe, the sql scripts to create the schema are in: C:\Windows\Microsoft.NET\Framework\[Framework version].
So for .Net 4, it would be: C:\Windows\Microsoft.NET\Framework\v4.0.30319
Both install and "uninstall" sql scripts are there - e.g.
InstallMembership.sql
UninstallMembership.sql
... and so on....

What parts of asp.net, c# and database should I use to create a forum like stackoverflow?

I am a fresher and I have got a project in asp.net and c#. I have to create a forum, something like stackoverflow, so I have studied asp.net, c# and sql server 2008 but now I am unsure how I should start work on this project.
What technology and what part of asp.net, c# and the database will I use more? I have 3 days to study so I want to know which parts of asp.net, database and c# I have to cover in 3 days.
It's my first live project, will I have to study any other languages or are the ones listed enough?
Session management, good understanding about web controls and user control.
and just go throgh ado.net if u are using asp.net.
Maybe you should try to use ASP.net mvc check this link.
If you are going to use sql server as database / Backend of you application than
start getting infomation about linq to sql >>
LINQ to SQL: .NET Language-Integrated Query for Relational Data
or you can also go for entity framework
The ADO.NET Entity Framework Overview

ASP.NET MVC 2 Embedded Database

I am building a very small temprorary website that needs a small backing store. I have built this in ASP.NET MVC 2, and wanted to host with DiscountASP - although this isn't essential.
I would like an backing store that will work with ASP.NET MVC 2, VS2010 Express, enabled LINQ (or EF) and work without further charges on a shared host.
From my investigation, SQLCE 3.5 doesn't work in .NET 4
SQLCE 4, is only CTP and doesn't work in VS2010
SQlite doesn't have any .NET 4.0 drivers.
HAve I got this right? Any good tutorials or blogs that show how to get this working step by step?
Thanks,
Mark
SQLite does work on .Net 4.0. Here are some other very similar questions about embedded databases in .NET:
Good embedded database solution (like SQLite) for .Net
Embedded database for .net
Open Source Embedded Database Options for .Net Applications
I'm not an ASP expert but have you heard about Firebird SQL? Database engine which has client/server or embeded versions, fully featured with transactions etc. and with ADO.NET provider
http://firebirdsql.org/dotnetfirebird/
http://firebirdsql.org/index.php?op=devel&sub=netprovider
No, Dont even think about using firebird embedded in ASP.NET.
It is strictly forbidden.
here's a reference on Firbird website tell you to avoid:
Is it possible to use the embedded Firebird in my ASP.NET application?
Yes. But Firebird ADO.NET looks for the fbembed.dll file in the application working directory. For ASP.NET application the working directory is the system folder (e.g. C:\WINDOWS\System32). But it's not without problems
link text
On Another page from the same website:
ASP.NET uses a feature that help against poorly written ASP.NET application to block the entire server - it recycles the ASP.NET working process both regularly. By default, IIS6 uses overlapped recycling where there is a new process started before the old is stopped to ensure uninterrupted operation. The problem is that the fbembed.dll exclusively locks the database for the owner process so if you run another process simultaneously the database won't be accessible before the first process stops. You might want to accept this but it really is not an optimal solution.
The solution is to turn off the overlapped recycle (by setting the DisallowOverlappingRotation metabase property to true). However, this might cause outages of your application during recycle.
Conclusion
Don't do tha**t ;-). Really, fbembed.dll **was not built to handle such use. You can make it work but it is just a hack.

Resources