我想知道是否有人能够为我提供一些关于创建 C# 程序集的指导或书籍推荐,该程序集将加载到 sqlserver 中并在新数据进入时在数据库上运行。
背景:
我有几年的 Java 经验,并且创建了一种算法来运行从 SQL 查询检索的数据。我的雇主现在希望我将其创建为 ac# 程序集,该程序集直接位于数据库上,并在数据进入时(或定期点)执行分析,并在数据高于特定阈值时发出警报。
我从来没有用 C# 编写过代码,但我听说它与 Java 非常相似。 C# 的学习不是我的问题,我认为我可以从在线资源中获取。我在查找信息时遇到困难的是程序集以及它如何与 sqlserver 相关联/是否需要在代码中执行任何特定操作才能使其工作。
我一直在网上浏览 Microsoft 的 msdn 库以获取想法,我认为我正在寻找的是 C# SQL CLR 数据库项目
。
这对于我想要实现的目标来说正确吗?如果是的话,有人在处理这个问题时有任何提示/需要注意的事情吗?
ps. 有没有办法以某种方式直接处理表格?而不是像我使用 Java 那样不断地对数据执行查询?我不确定这是否可能,但我认为可能是因为程序集以某种方式直接连接到数据库。
I was wondering if anyone would be able to provide me with some guidance or book recommendations on creating a C# assembly that will be loaded into sqlserver and run on the database as new data comes in.
Background:
I have a few years of Java experience and had created an algorithm to run against data retrieved from a sql query. My employer now wants me to create it as a c# assembly that sits on the database directly and performs the analysis as data comes in (or at periodic points) and sends out alerts if they are above a certain threshold.
I have never coded in c# but I am told that it is very similar to Java. The learning of c# is not my issue here, I think that I can pick that up from online resources. What I am having trouble finding information on is the assembly and how it ties into sqlserver / if there needs to be anything specific done in the code for it to work.
I have been browsing Microsoft's msdn library online to get an idea and I think that what I am looking for is a C# SQL CLR Database Project
.
Is this correct for what I am trying to accomplish? If so does anybody have any tips / things to look out for when working on this?
ps. Is there a way to deal directly with the tables in some manner? Instead of constantly performing a query on the data like I do with Java? I am not sure if this is possible but I thought it may be since the assembly is connected directly to the database somehow.
发布评论
评论(2)
您可以做的是使用 c# 构建 用户定义SQL Server 的函数。要让此函数在插入新数据时运行,您可以编写一个触发器 对于在 插入的表格。
What you can do is use c# to build user defined functions for sql server. To get this function to run as new data is inserted, you can write a trigger for the relevant tables that call the function as part of a select query on the inserted table.
查看 Simple Talk 上的这篇介绍文章:
构建我的第一个 SQL Server 2005 CLR
它很好地展示了如何构建 SQL CLR 程序集并从 SQL Server 内部使用它。
Check out this intro article at Simple Talk:
Building my First SQL Server 2005 CLR
It shows quite nicely how to approach building a SQL CLR assembly and using it from inside SQL Server.