小编Equ*_*xor的帖子

您应该重用SqlConnection,SqlDataAdapter和SqlCommand对象吗?

我正在使用以类似于以下代码的布局编写的DAL对象.我简化了很多代码只是为了显示设置.

public class UserDatabase : IDisposable
{
    private SqlDataAdapter UserDbAdapter;
    private SqlCommand UserSelectCommand;
    private SqlCommand UserInsertCommand;
    private SqlCommand UserUpdateCommand;
    private SqlCommand UserDeleteCommand;

    private System.Data.SqlClient.SqlConnection SQLConnection; 

    public UserDatabase()
    {
        this.SQLConnection = new System.Data.SqlClient.SqlConnection(ConnectionString);
        this.UserDbAdapter= new SqlDataAdapter(); 
        this.UserDbAdapter.DeleteCommand = this.UserDeleteCommand;
        this.UserDbAdapter.InsertCommand = this.UserInsertCommand;
        this.UserDbAdapter.SelectCommand = this.UserSelectCommand;
        this.UserDbAdapter.UpdateCommand = this.UserUpdateCommand;
    }

    private bool FillUsers(DataSet UserDataSet, out int numberOfRecords)
    {
        bool success = true;

        numberOfRecords = 0;
        string errorMsg = null;

        this.UserDbAdapter.SelectCommand = this.GetUsersSelectCommand();

        numberOfRecords = UserDbAdapter.Fill(UserDataSet, UsersTableName);

        return success;
    }

    private SqlCommand GetUserSelectCommand() …
Run Code Online (Sandbox Code Playgroud)

c# sqlcommand sqlconnection sqldataadapter

7
推荐指数
1
解决办法
5926
查看次数

udf vs直接sql性能

使用MSSQL 2005

我今天在一个where语句中用Scalar UDF来玩,看看与调用和io差异等相关的一些成本.

我从2个基本表开始.客户有100万行.和购买有100,000.两者都有一个自动标识列作为主键.没有定义其他索引.

DBCC FREEPROCCACHE
DBCC DROPCLEANBUFFERS

SET STATISTICS IO ON
    SELECT * FROM Customer C 
    INNER JOIN Purchases P on C.[IDENTITY] = P.CustomerID
    WHERE P.Amount > 1000
SET STATISTICS IO OFF
Run Code Online (Sandbox Code Playgroud)

这将返回IO的统计信息

Table 'Customer'. Scan count 0, logical reads 3295, physical reads 1, read-ahead reads 32, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'Purchases'. Scan count 1, logical reads 373, physical reads 1, read-ahead reads 370, lob logical reads 0, lob …
Run Code Online (Sandbox Code Playgroud)

sql optimization sql-server-2005 user-defined-functions

5
推荐指数
1
解决办法
554
查看次数