Ran*_*ser 4 .net c# using sqlclient asp.net-mvc-4
我的问题可能是愚蠢的,或者根本不是一个问题,但在这里......
我在我的ASP.net MVC项目中执行了一些数据库操作,我每次创建两个对象,SqlConnection
和SqlCommand
.
我在下面展示了一个例子
using (SqlConnection connection = new SqlConnection(connectionString))
{
using (SqlCommand command = new SqlCommand("sRegisterUser", connection))
{
Run Code Online (Sandbox Code Playgroud)
我在不同方法的一个类中进行所有这些不同的操作.
我的问题是如何每次都减少这些对象的创建?我如何在全球范围内创建它们
PS:sRegisterUser是一个存储过程,就像明智的其他方法一样,使用不同的过程,它们将不同的值作为参数.
请帮帮我.
在此先感谢您的帮助.
Mik*_*oud 11
答案是,不要.你不希望共享这些对象,你正确使用它们.