如何在不使用数据实体框架的情况下将sql server与asp.net mvc3应用程序连接起来 [英] how to Connect sql server with asp.net mvc3 application without using data entity framwork

查看:75
本文介绍了如何在不使用数据实体框架的情况下将sql server与asp.net mvc3应用程序连接起来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用asp.net mvc3应用程序连接sql server而不使用数据实体framwork

how to Connect sql server with asp.net mvc3 application without using data entity framwork

推荐答案

SQL Server,ASP.NET MVC和实体框架......无这些框架取决于其他框架。它们彼此使用只是为了提供更多特性和功能。例如,如果我要创建一个我不需要提交数据或表单的网站,我可以使用ASP.NET MVC创建它,而无需为SQL Server或Entity Framework添加任何数据控制器。



使用 System.Data.SqlClient [ ^ ]命名空间。它为您提供连接对象,参数(用于防止SQL注入),命令和其他所需的东西。您可以使用它们进行连接。例如,



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,

// 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
}





完全不需要ASP.NET MVC或Entity Framework来建立与SQL Server的连接。 SQL Server所需的东西是:



1.有效的SQL Server。

- 这是响应您的请求的内容。

2.表示连接方法的连接字符串。

- 服务器名称

- 数据库名称(可选,以后可以更改)

- 凭据或身份验证类型。



这些可以让你连接。但是,我还有一篇文章,仅使用C#连接到数据库(没有ASP.NET MVC或实体框架依赖)。 如何将SQL数据库连接到C#程序,初学者教程 [ ^ ]


这篇关于如何在不使用数据实体框架的情况下将sql server与asp.net mvc3应用程序连接起来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆