当数据库处于活动状态并且更改频繁时,SQL/CLR 集成需要考虑哪些因素?

发布于 2024-10-08 10:33:47 字数 787 浏览 0 评论 0原文

刚刚第一次创建了一个 CLR 函数并将其部署到数据库中,在阅读了一些关于它的工作原理之后,我认为这对于像我这样的 C# 程序员来说是一个不错的选择。

我的问题:如果我按“control F5”并让 VS 将我的用户定义函数等神奇地部署到我的数据库 - 如果当前使用以前的版本连接到该数据库怎么办?

我希望一切顺利。

如果它会导致正在进行的查询返回错误,我必须等到可以使用适当的开发环境的时候。

编辑:我决定根据上次使用此标签发布时的反馈,首先放入我将要使用的内容。

我不想用两种语言维护逻辑,所以我将把以下内容转换为 C#:

CREATE FUNCTION [dbo].[tousd] 
(@Currency char(3), @Amount money)
RETURNS money
AS
BEGIN
declare @Return money
if(@Currency = 'USD')
    return @Amount * 1.0
else if(@Currency = 'EUR')
    return (@Amount * 1.3065)
else if(@Currency = 'GBP')
    return (@Amount * 1.5552)
else if(@Currency = 'CAD')
    return (@Amount * 0.9789)
else if(@Currency = 'AUD')
    return (@Amount * 0.9613)
else
    return 0.0
return @Return
end

提前致谢, 亚伦

I just now for the very first time made a CLR function and deployed it into a database, and after reading a little about how it works, think it's a good option for a C# programmer like me.

My question: if I press "control F5" and let VS do it's magic deploy of my user defined functions, etc, to my database -- what if there are current connections to that database using the previous version?

My hope is that it would be seamless.

If it would cause a query in progress to return an error, I have to wait until the time when a proper development environent can be used.

EDIT: I decided to put in what I'm going to use this for first based on feedback last time I posted with this tag.

I don't want to maintain logic in two languages, so I'm going to convert the following to C#:

CREATE FUNCTION [dbo].[tousd] 
(@Currency char(3), @Amount money)
RETURNS money
AS
BEGIN
declare @Return money
if(@Currency = 'USD')
    return @Amount * 1.0
else if(@Currency = 'EUR')
    return (@Amount * 1.3065)
else if(@Currency = 'GBP')
    return (@Amount * 1.5552)
else if(@Currency = 'CAD')
    return (@Amount * 0.9789)
else if(@Currency = 'AUD')
    return (@Amount * 0.9613)
else
    return 0.0
return @Return
end

Thanks in advance,
Aaron

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡淡的优雅 2024-10-15 10:33:47

不要仅仅因为您更习惯它而将 tsql 转换为 C#。数据库经过优化,可以最好地与 SQL 配合使用,而不是与 C# 配合使用。 CLR 只能做 SQL 不能做的事情。如果可以用 SQl 完成,就用 SQL 完成。

在拥有真正的开发环境之前,不要再做任何工作。乱搞人们实际使用的东西是不专业的,对数据来说也是危险的,并且可能很快就会失去你的客户。

Do not convert tsql to C# just becasue you are more comfortable with it. Databases are optimized to work best with SQL not C#. CLRs are only available to do things that SQL cannot do. If you can do it in SQl, do it in SQL.

Do not do any more work until you have a real dev environment. Mucking around with stuff people are actually using is unprofessional and dangerous to the data and can quickly lose your customers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文