如何使用企业库将参数发送到存储过程

时间:2014-03-27 11:37:55

标签: database logging parameters enterprise-library procedure

我必须在数据库中记录Exception,我已经创建了pprocedure,配置了数据库跟踪侦听器,但我不明白,如何将参数发送到数据库中的存储过程,应该配置什么?< / p>

1 个答案:

答案 0 :(得分:0)

/*
    using System;
    using System.Collections.Generic;
    using System.Text;

    using System.Data;
    using System.Data.Common;
    using System.Data.Odbc;
    using System.Data.OleDb;

    using Microsoft.Practices.EnterpriseLibrary.Data;
    using Microsoft.Practices.EnterpriseLibrary.Data.Configuration;
    using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
*/        

        public int DeleteSomething(System.Guid userUUID)
        {
            int rowsAffected = 0;
            try
            {
                Database db = this.GetDatabase();
                DbCommand dbc = db.GetStoredProcCommand("dbo.uspDeleteSomething");
                dbc.CommandTimeout = 600;

                db.AddInParameter(dbc, "@UserUUID", System.Data.DbType.Guid,  userUUID );

                rowsAffected = db.ExecuteNonQuery(dbc);
            }
            finally
            { }

            return rowsAffected;
        }


        protected Microsoft.Practices.EnterpriseLibrary.Data.Database GetDatabase()        
        {
            Database returnDb;
            returnDb = Microsoft.Practices.EnterpriseLibrary.Data.DatabaseFactory.CreateDatabase();
            return returnDb;
        }