当前位置: 首页>>代码示例>>C#>>正文


C# SqlDependency.AddCommandDependency方法代码示例

本文整理汇总了C#中System.Data.SqlClient.SqlDependency.AddCommandDependency方法的典型用法代码示例。如果您正苦于以下问题:C# SqlDependency.AddCommandDependency方法的具体用法?C# SqlDependency.AddCommandDependency怎么用?C# SqlDependency.AddCommandDependency使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.SqlClient.SqlDependency的用法示例。


在下文中一共展示了SqlDependency.AddCommandDependency方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IsInMaintenanceMode

        public static bool IsInMaintenanceMode()
        {
            bool inMaintenanceMode;
            string connStr = "Data Source=KIM-MSI\\KIMSSQLSERVER;Initial Catalog=MVWDataBase;User ID=sa;Password=mis123;MultipleActiveResultSets=True";
            if (MemoryCache.Default["MaintenanceMode"] == null)
            {
                Console.WriteLine("Hitting the database...");
                CacheItemPolicy policy = new CacheItemPolicy();
                SqlDependency.Start(connStr);
                using (SqlConnection conn = new SqlConnection(connStr))
                {
                    using (SqlCommand command = new SqlCommand("Select MaintenanceMode From dbo.MaintenanceMode", conn))
                    {
                        command.Notification = null;
                        SqlDependency dep = new SqlDependency();
                        dep.AddCommandDependency(command);
                        conn.Open();
                        inMaintenanceMode = (bool)command.ExecuteScalar();
                        SqlChangeMonitor monitor = new SqlChangeMonitor(dep);
                        policy.ChangeMonitors.Add(monitor);
                        dep.OnChange += Dep_OnChange;
                    }
                }

                MemoryCache.Default.Add("MaintenanceMode", inMaintenanceMode, policy);
            }
            else
            {
                inMaintenanceMode = (bool)MemoryCache.Default.Get("MaintenanceMode");
            }

            return inMaintenanceMode;
        }
开发者ID:kimx,项目名称:CacheMemoryMeasureLab,代码行数:33,代码来源:MemoryCacheMonitor.cs

示例2: SomeMethod

        public DataTable SomeMethod(Action<object, SqlNotificationEventArgs> handler)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                // notificationas bus iskvieciamas visuomet, kai pasikeis bent vienas duomuo, is sio SELECTO grazinamu duomenu set`o (bus atliktas UPDATE, DELETE, INSERT)
                using (SqlCommand command = new SqlCommand("SELECT StudentasID, Vardas, Pavarde, IBAN, AK FROM dbo.tblIseiviaiStudentai", connection))
                {

                    dependency = new SqlDependency();
                    command.Notification = null;

                    dependency.AddCommandDependency(command);
                    dependency.OnChange += new OnChangeEventHandler(handler);

                    if (connection.State != ConnectionState.Open)
                    {
                        connection.Open();
                    }

                    // kad veiktu notificationas butini sie conection`o nustatymai, kitaip eventas bus kvieciamas nuolatos
                    var ON_PARAMETERS = @"SET ANSI_NULLS, ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER, ARITHABORT ON";
                    var OFF_PARAMETERS = @"SET NUMERIC_ROUNDABORT OFF";
                    var cmd_ON_PARAMETERS = new SqlCommand(ON_PARAMETERS, connection);
                    var cmd_OFF_PARAMETERS = new SqlCommand(OFF_PARAMETERS, connection);
                    cmd_ON_PARAMETERS.ExecuteNonQuery();
                    cmd_OFF_PARAMETERS.ExecuteNonQuery();

                    dataTable.Clear();
                    dataTable.Load(command.ExecuteReader(CommandBehavior.CloseConnection));
                    dependency = null;
                    return dataTable;
                }
            }
        }
开发者ID:llenroc,项目名称:AutoNotification,代码行数:34,代码来源:Notification.cs

示例3: SetMonitor

 public static void SetMonitor()
 {
     string connStr = ConfigurationManager.ConnectionStrings["lab"].ConnectionString;
     CacheItemPolicy policy = new CacheItemPolicy();
     SqlDependency.Start(connStr);
     using (SqlConnection conn = new SqlConnection(connStr))
     {
         using (SqlCommand command = new SqlCommand("Select MaintenanceMode From dbo.MaintenanceMode", conn))
         {
             command.Notification = null;
             SqlDependency dep = new SqlDependency();
             dep.AddCommandDependency(command);
             conn.Open();
             bool inMaintenanceMode = (bool)command.ExecuteScalar();
             SqlChangeMonitor monitor = new SqlChangeMonitor(dep);
             policy.ChangeMonitors.Add(monitor);
             dep.OnChange += Dep_OnChange;
             MemoryCache.Default.Add("MaintenanceMode", inMaintenanceMode, policy);
         }
     }
 }
开发者ID:kimx,项目名称:CacheMonitorLab,代码行数:21,代码来源:MemoryCacheMonitor.cs

示例4: CreateSqlDep

        void CreateSqlDep(SqlCommand sqlCmd) {
            _sqlYukonDep = new SqlDependency();

            // Note: sqlCmd is null in output cache case.
            
            if (sqlCmd != null) {
                Debug.Trace("SqlCacheDependency", "SqlCmd added to SqlDependency object");
                _sqlYukonDep.AddCommandDependency(sqlCmd);
            }
            
            _sqlYukonDep.OnChange += new OnChangeEventHandler(OnSQL9SqlDependencyChanged);
            
            Debug.Trace("SqlCacheDependency", "SQL9 dependency created: depId=" + _sqlYukonDep.Id);
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:14,代码来源:SqlCacheDependency.cs


注:本文中的System.Data.SqlClient.SqlDependency.AddCommandDependency方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。