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


C# SqlClient.SqlDependency类代码示例

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


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

示例1: SqlChangeMonitor

		public SqlChangeMonitor (SqlDependency dependency)
		{
			if (dependency == null)
				throw new ArgumentNullException ("dependency");
			
			throw new NotImplementedException ();
		}
开发者ID:stabbylambda,项目名称:mono,代码行数:7,代码来源:SqlChangeMonitor.cs

示例2: GetData

        public IEnumerable<JobInfo> GetData()
        {
            using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["KPIConnectionString"].ConnectionString))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand(@"SELECT [JobID],[Name],[LastExecutionDate],[Status] FROM [dbo].[JobInfo]", connection))
                {
                    // Make sure the command object does not already have
                    // a notification object associated with it.
                    command.Notification = null;

                    SqlDependency dependency = new SqlDependency(command);
                    dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);

                    if (connection.State == ConnectionState.Closed)
                        connection.Open();

                    using (var reader = command.ExecuteReader())
                        return reader.Cast<IDataRecord>()
                            .Select(x => new JobInfo()
                            {
                                JobID = x.GetInt32(0),
                                Name = x.GetString(1),
                                LastExecutionDate = x.GetDateTime(2),
                                Status = x.GetString(3)
                            }).ToList();

                }
            }
        }
开发者ID:nietzky,项目名称:SignalR10,代码行数:30,代码来源:Global.asax.cs

示例3: UpdateGrid

        private static void UpdateGrid()
        {
            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                //依赖是基于某一张表的,而且查询语句只能是简单查询语句,不能带top或*,同时必须指定所有者,即类似[dbo].[]
                using (SqlCommand command = new SqlCommand("select ID,UserID,[Message] From [dbo].[Messages] where id>0", connection))
                {
                    command.CommandType = CommandType.Text;
                    connection.Open();
                    SqlDependency dependency = new SqlDependency(command);
                    dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);

                    using (SqlDataReader sdr = command.ExecuteReader())
                    {
                        Console.WriteLine();
                        while (sdr.Read())
                        {
                            Console.WriteLine(
                                "Id:{0}\tUserId:{1}\tMessage:{2}",
                                sdr["ID"].ToString(), sdr["UserId"].ToString(),
                                sdr["Message"].ToString()
                                );
                        }
                    }

                }
            }
        }
开发者ID:henrydem,项目名称:yongfa365doc,代码行数:28,代码来源:AboutSqlDependency.cs

示例4: RegisterForChanges

        public string[] RegisterForChanges()
        {
            string[] result = null;

            using (SqlConnection conn = new SqlConnection(mSubscriberConnectionString))
            {
                if (conn.State != ConnectionState.Open) conn.Open();

                using (SqlCommand cmd = new SqlCommand("SELECT [BilgilendirmeTipi],[Baslik],[Icerik] FROM [dbo].[Bilgilendirmeler]", conn))
                {
                    SqlDependency dependency = new SqlDependency(cmd);
                    dependency.OnChange += new OnChangeEventHandler(OnNotificationChange);

                    using (SqlDataAdapter adap = new SqlDataAdapter(cmd))
                    {
                        using (DataTable dt = new DataTable())
                        {
                            adap.Fill(dt);
                            if (dt.Rows.Count > 0)
                            {
                                result = new string[3];

                                result[0] = (string)dt.Rows[0][0];
                                result[1] = (string)dt.Rows[0][1];
                                result[2] = (string)dt.Rows[0][2];
                            }
                        }
                    }
                }
            }

            return result;
        }
开发者ID:sertunc,项目名称:SqlDependencyOrnekleri,代码行数:33,代码来源:Form1.cs

示例5: Enlist

		public ChangeMonitor Enlist()
		{
			using (var connection = new SqlConnection(connectionString))
			{
				using (var exeCommand = new System.Data.SqlClient.SqlCommand(command, connection))
				{
					//is the command a sproc
					if (isStoredProcedure)
					{
						exeCommand.CommandType = CommandType.StoredProcedure;
					}

                    if (commandTimeout.HasValue)
				        exeCommand.CommandTimeout = this.commandTimeout.Value;

					var dependency = new SqlDependency(exeCommand);
                    var monitor = new SqlChangeMonitor(dependency);

					connection.Open();
					exeCommand.ExecuteNonQuery();

					return monitor;

				}
			}
		}
开发者ID:romis2012,项目名称:NHibernate.Caches.SysCache3,代码行数:26,代码来源:SqlCommandCacheDependencyEnlister.cs

示例6: DataBase

 public DataBase()
 {
     ConnectToDB();
     sqlDependency = new SqlDependency();
     //sqlDependency.AddCommandDependency(new SqlCommand("INSERT", conn));
     sqlDependency.OnChange += new OnChangeEventHandler(onChange);
 }
开发者ID:YourTradingSystems,项目名称:4XGain,代码行数:7,代码来源:DataBase.cs

示例7: GetPersons

        public IEnumerable<Person> GetPersons()
        {
            using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand(@"SELECT [ID],[FirstName],[LastName] FROM [dbo].[Person]", connection))
                {
                    command.Notification = null;

                    var dependency = new SqlDependency(command);
                    dependency.OnChange += (x, y) => _hubContext.Clients.All.displayStatus(GetPersons());

                    using (var reader = command.ExecuteReader())
                    {
                        return reader.Cast<IDataRecord>()
                        .Select(x => new Person
                        {
                            ID = x.GetInt64(0),
                            FirstName = x.GetString(1),
                            LastName = x.GetString(2),
                        }).ToList();
                    }
                }
            }
        }
开发者ID:Rookian,项目名称:SignalR,代码行数:25,代码来源:Repository.cs

示例8: GetAllMessages

        public IEnumerable<Messages> GetAllMessages()
        {
            var messages = new List<Messages>();
            using (var connection = new SqlConnection(_connString))
            {
                connection.Open();
                using (var command = new SqlCommand(@"SELECT [MessageID], [Message], [EmptyMessage], [Date] FROM [dbo].[Messages]", connection))
                {
                    command.Notification = null;

                    var dependency = new SqlDependency(command);
                    dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);

                    if (connection.State == ConnectionState.Closed)
                        connection.Open();

                    var reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        messages.Add(item: new Messages { MessageID = (int)reader["MessageID"], Message = (string)reader["Message"], EmptyMessage =  reader["EmptyMessage"] != DBNull.Value ? (string) reader["EmptyMessage"] : "", MessageDate = Convert.ToDateTime(reader["Date"]) });
                    }
                }

            }
            return messages;
        }
开发者ID:JairNunes,项目名称:signalrdatabasenotifications,代码行数:27,代码来源:MessagesRepository.cs

示例9: GetAllMessagesLog

        public IEnumerable<MessageLog> GetAllMessagesLog()
        {
            string conStr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
               SqlConnection connection = new SqlConnection(conStr);

               string query = "SELECT Message,EventID,LL.Name as LogLevelID,OC.Name as OperationCodeID,ML.ServerName,ML.ComponentName,ML.SubComponentName FROM [dbo].[MessageLog] ML inner join [dbo].[LogLevel] LL on ML.LogLevelID = LL.ID inner join [dbo].[OperationCode] OC on ML.OperationCodeID = OC.ID";
               SqlDependency.Start(conStr);
               SqlCommand command = new SqlCommand(query, connection);
               SqlDependency dependency = new SqlDependency(command);

               //If Something will change in database and it will call dependency_OnChange method.
               dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);
               connection.Open();
               SqlDataAdapter da = new SqlDataAdapter(command);
               DataTable dt = new DataTable();
               da.Fill(dt);

               List<MessageLog> messageList = new List<MessageLog>();
               for (int i = 0; i < dt.Rows.Count; i++)
               {
               MessageLog ml = new MessageLog();
               ml.Name = dt.Rows[i]["Message"].ToString();
               ml.EventID = Convert.ToInt32(dt.Rows[i]["EventID"].ToString());
               ml.LogLevelName = dt.Rows[i]["LogLevelID"].ToString();
               ml.OperationCodeName = dt.Rows[i]["OperationCodeID"].ToString();
               ml.ServerName = dt.Rows[i]["ServerName"].ToString();
               ml.ComponentName = dt.Rows[i]["ComponentName"].ToString();
               ml.SubComponentName = dt.Rows[i]["SubComponentName"].ToString();
               messageList.Add(ml);
               }
               return messageList;
        }
开发者ID:dotnext24,项目名称:SignalIR,代码行数:32,代码来源:NotificatiobHub.cs

示例10: RegisterDiscussMessages

        public List<DiscussMessageModel> RegisterDiscussMessages()
        {
            var messageChat = new List<DiscussMessageModel>();
            using (var connection = new SqlConnection(_connString))
            {
                connection.Open();
                using (var command = new SqlCommand(@"SELECT *
                                                      FROM [dbo].[Comments]", connection))
                {
                    command.Notification = null;
                    var dependency = new SqlDependency(command);
                    dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);
                    if (connection.State == ConnectionState.Closed)
                        connection.Open();

                    var reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        messageChat.Add(item: new DiscussMessageModel
                        {
                            Id = reader["Id"].ToString(),
                            Username = reader["Username"].ToString(),
                            Message = reader["Message"].ToString(),
                            FilePath = reader["FilePath"].ToString(),
                            Avatar = "dist/img/avatar.png",
                            Status = reader["Status"].ToString(),
                            CreatedDate = DateTime.Parse(reader["CreatedDate"].ToString())
                        });
                    }
                }

            }
            return messageChat;
        }
开发者ID:vanan08,项目名称:ADSoft,代码行数:34,代码来源:1448120134$DiscussMessageRepository.cs

示例11: GetData

        public IEnumerable<Message> GetData()
        {
            using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand("SELECT [ID], [Date], [Message] FROM [dbo].[Messages]", connection))
                {
                    command.Notification = null;

                    SqlDependency dependency = new SqlDependency(command);
                    dependency.OnChange += DependencyOnChange;

                    if (connection.State == ConnectionState.Closed)
                        connection.Open();

                    using (var reader = command.ExecuteReader())
                        return reader.Cast<IDataRecord>()
                            .Select(x => new Message()
                            {
                                ID = x.GetInt32(0),
                                Date = x.GetDateTime(1),
                                Text = x.GetString(2)
                            }).ToList();
                }
            }
        }
开发者ID:vmeln,项目名称:signalr-scaling,代码行数:26,代码来源:Message.cs

示例12: RegisterDiscussMessages

        public void RegisterDiscussMessages()
        {
            using (var connection = new SqlConnection(_connString))
            {
                connection.Open();
                using (var command = new SqlCommand(@"SELECT [Id]
                                                          ,[Username]
                                                          ,[Message]
                                                          ,[FilePath]
                                                          ,[Status]
                                                          ,[CreatedDate]
                                                      FROM [dbo].[Discuss] ORDER BY [dbo].[Discuss].CreatedDate desc", connection))
                {
                    command.Notification = null;

                    var dependency = new SqlDependency(command);
                    dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);

                    if (connection.State == ConnectionState.Closed)
                        connection.Open();

                    var reader = command.ExecuteReader();

                }

            }
           
        }
开发者ID:vanan08,项目名称:ADSoft,代码行数:28,代码来源:1448036558$DiscussMessageRepository.cs

示例13: 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

示例14: SqlDependencyCacheWatcher

 public SqlDependencyCacheWatcher(string tableName)
 {
     this.connectionString = connectionString;
     this.sqlQueue = sqlQueue;
     this.listenerQuery = listenerQuery;
     this.dependency = null;
 }
开发者ID:Gotik88,项目名称:LoanProcess,代码行数:7,代码来源:SqlDependencyCacheWatcher.cs

示例15: 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


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