我有一个MSSQL表,其中包含我的Windows服务应根据时间戳处理的计划任务,我想知道我有什么选择来轮询这样的表
SELECT *
FROM mydb
WHERE SYSUTCDATE() >= timestamp
Run Code Online (Sandbox Code Playgroud)
我可能需要至少每5秒轮询一次表格.基本上我希望我的Windows服务在表中的时间戳设置的时间处理数据.
对我来说,这似乎不是最有效的方式.我已经研究过DML和CLR触发器,我认为它们不会起作用,因为它们会在数据发生变化时触发,而不是在时间戳已经过去时触发.思考?
更新2:
我已经意识到把它称为"预定任务"是一个糟糕的措辞选择,所以我将尝试更详细地描述它.
该项目的目标是根据我们的业务逻辑向人们发送电话通知.一种情况是应该根据内部事件在特定时间打电话给多个人.可以多次呼叫同一个人,具体取决于电话呼叫的应答方式.因此,为了简化操作并消除管理每个电话呼叫状态的复杂性和开销,我认为通过将每个电话呼叫作为表中的条目来预先安排每个电话呼叫是个好主意.应停止通知时,将从表中删除待处理的电话呼叫.这将使Windows服务的设计变得非常简单.它所做的就是根据表中的时间戳发送通知.
更新1:
消息队列
我还没弄明白发件人如何在适当的时候将消息放入队列.
的SqlDependency
我使用来自使用SqlDependency检测更改的示例代码时遇到问题.由于某种原因,OnChange事件最初只会被触发,以后什么都不会发生.
更新:我不认为SqlDependency会工作,因为表中的数据不会更改以使触发器触发.
void Initialization()
{
// Create a dependency connection.
SqlDependency.Start(connectionString, queueName);
}
void SomeMethod()
{
// Assume connection is an open SqlConnection.
// Create a new SqlCommand object.
using (SqlCommand command=new SqlCommand(
"SELECT timestamp,othercolumn FROM mydb WHERE SYSUTCDATE() >= timestamp",
connection))
{
// Create a dependency and associate it with the SqlCommand.
SqlDependency dependency=new SqlDependency(command);
// Maintain the refence …Run Code Online (Sandbox Code Playgroud) 在我的 Windows 服务中,我需要能够检索存储在同一网络上的 SQL Server 2012 数据库中的第三方 REST API 的凭据。我的每个客户可能都分配有不同的 API 凭证。例如:
Customer Name | API ID | API Password In Plain Text
-----------------------------------------------------
Customer 1 1234 somepassword
Customer 2 1234 somepassword
Customer 3 5678 anotherpassword
Run Code Online (Sandbox Code Playgroud)
在此服务的第一次迭代中,所有客户都使用相同的 API 凭据,并使用SectionInformation.ProtectSection在 Windows 服务的 app.config 中对其进行加密。
我是否只使用 .NET 框架提供的加密/解密方法之一并将该值存储在数据库中?例如,此处提供的解决方案之一:Encrypting & Decrypting a String in C# ? 我可以研究任何建议或其他解决方案?
我有一个看起来像这样的表:
UserID Email
-----------------------------------
1 1_0@email.com;1_1@email.com
2 2_0@email.com;2_1@email.com
3 3_0@email.com;3_3@email.com
Run Code Online (Sandbox Code Playgroud)
我需要创建一个如下所示的临时表:
UserID Email
-----------------------------------
1 1_0@email.com
1 1_1@email.com
2 2_0@email.com
2 2_1@email.com
3 3_0@email.com
3 3_1@email.com
Run Code Online (Sandbox Code Playgroud)
临时表将用于更新触发器,我想知道是否有比这样做更优雅的方法:
-- Create temp table to hold the result table
CREATE TABLE #resultTable(
UserID int,
Email nvarchar(50)
)
-- Create temp table to help iterate through table
CREATE TABLE #tempTable(
ID int IDENTITY(1,1),
UserID int,
Email nvarchar(50)
)
-- Insert data from updated table into temp table
INSERT INTO #tempTable
SELECT [UserId], [Email]
FROM …Run Code Online (Sandbox Code Playgroud)