Click here to Skip to main content
16,016,425 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to Connect sql server with asp.net mvc3 application without using data entity framwork
Posted

1 solution

SQL Server, ASP.NET MVC and Entity Framework... None of these frameworks depend on other framework. They are used with each other just to provide more features and functionality. For example if I am going to create a website where I do not need data or forms being submitted, I can create it using ASP.NET MVC without adding any data controllers for SQL Server or Entity Framework.

Connections to SQL Server are made using the objects provided under System.Data.SqlClient[^] namespace. It provides you with connection object, parameters (for prevention from SQL Injection), commands and other required stuff. You can use them to connect. For example,

C#
// SqlClient implements IDisposable
using (var connection = new SqlConnection("data-connection-string")) {
   connection.Open(); // Open the connection before initiating commands.

   var command = new SqlCommand("YOUR SQL COMMAND", connection);
   // execute the command
}


There is no need for ASP.NET MVC or Entity Framework at all just to establish the connection to SQL Server. The things that you need for SQL Server are:

1. A valid SQL Server.
- This is what responds to your request.
2. A connection string that represents method of connections.
- Server name
- Database name (optional, can be changed later)
- Credentials or authentication type.

These would allow you to connect. However, I also have an article for connecting to a database using C# only (no ASP.NET MVC or Entity Framework dependency). How to connect SQL Database to your C# program, beginner's tutorial[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900