部署期间 CLR 存储过程的架构

发布于 2024-10-05 10:30:00 字数 288 浏览 0 评论 0原文

我对配置 Visual Studio (2010) 感兴趣,以便在部署 C# CLR 数据库项目时,它将内容放入 DBO 以外的架构中。我知道我可以更新它手动创建的函数/过程/等包装器来实现这一点: CLR 存储过程:如何设置架构/所有者?

但是,我真的很想以某种方式自动化该过程。如果有人知道,我真的很感激答案!

I'm interested in configuring Visual Studio (2010) so that when deploying C# CLR Database projects, it puts stuff in schemas other than DBO. I understand I can update the function/procedure/etc... wrappers it creates manually to make this happen:
CLR Stored Procedures: how to set the schema/owner?

However, I'd really like to automate the process somehow. If anybody knows, I'd really appreciate the answer!

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

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

发布评论

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

评论(5

梦归所梦 2024-10-12 10:30:00

您可以使用以下命令将存储过程从一种模式更改为另一种模式

ALTER SCHEMA Org TRANSFER dbo.spUdpateCompany

You can change stored procedure from one schema to another using

ALTER SCHEMA Org TRANSFER dbo.spUdpateCompany
↘人皮目录ツ 2024-10-12 10:30:00

应该提到的是,这个问题从 Visual Studio 2012 开始就已经过时了,它为生成的 T-SQL 包装对象提供了一个“默认架构”配置字段。以下答案顶部的“更新”部分也指出了这一点;-)

CLR 存储过程:如何设置架构/所有者?

It should be mentioned that this question is obsolete as of Visual Studio 2012 which has a "Default Schema" configuration field for the generated T-SQL wrapper objects. This has also been noted in the "Update" section at the top of the following answer ;-) :

CLR Stored Procedures: how to set the schema/owner?

长伴 2024-10-12 10:30:00

这似乎与安全相关并且是“按设计”完成的。 http://support.microsoft.com/kb/918346

It seems to be security related and done "by design". http://support.microsoft.com/kb/918346

氛圍 2024-10-12 10:30:00

您可以将每个对象的脚本放入部署后脚本中,如下所示。下面的脚本使用架构 [Org] 重新创建存储过程。希望这有帮助。

第 1 步 - 删除项目自动添加的存储过程,因为它是使用默认架构 [dbo] 创建的。

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[spUpdateCompany]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[spUpdateCompany]
GO

步骤 2 - 如果 [Org] 架构中已存在存储过程,则删除存储过程,并在 [Org] 架构中重新创建存储过程。

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Org].[spUpdateCompany]') AND type in (N'P', N'PC'))
DROP PROCEDURE [Org].[spUpdateCompany]
GO



CREATE PROCEDURE [Org].[spUpdateCompany]
    @Id int,
    @Name [nvarchar](4000)
WITH EXECUTE AS CALLER
AS
EXTERNAL NAME [SQLServerProject.CLR].[StoredProcedures].[spUpdateCompany]
GO

You may put scripts for each object in post deployment script like below. Below script re-creates stored procedure with schema [Org]. Hope this helps.

Step1 - Remove Stored procedure added automatically by project since it is created with default schema [dbo].

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[spUpdateCompany]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[spUpdateCompany]
GO

Step2 - Remove stored procedure if already exist in [Org] schema and re-create stored procedure in [Org] schema.

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[Org].[spUpdateCompany]') AND type in (N'P', N'PC'))
DROP PROCEDURE [Org].[spUpdateCompany]
GO



CREATE PROCEDURE [Org].[spUpdateCompany]
    @Id int,
    @Name [nvarchar](4000)
WITH EXECUTE AS CALLER
AS
EXTERNAL NAME [SQLServerProject.CLR].[StoredProcedures].[spUpdateCompany]
GO
甜心小果奶 2024-10-12 10:30:00

在 SSDT 项目的 SQLCLR 属性中,您可以关闭“生成 DDL”。然后,您可以创建自己的附加到 CLR 程序集的 SQL 对象。例如,将新的存储过程添加为

CREATE PROCEDURE [schema].[StoredProcedure]
@参数BIGINT NULL
AS 外部名称 [AssemblyNameFromProjectProperties].[ClassWithProcedure].[Method];
GO

这将允许您将不同的对象放入不同的模式中

In the SQLCLR properties for the SSDT project, you can turn off "Generate DDL". Then you can create your own SQL object that attaches to the CLR assembly. For example, add a new stored procedure as

CREATE PROCEDURE [schema].[StoredProcedure]
@parameter BIGINT NULL
AS EXTERNAL NAME [AssemblyNameFromProjectProperties].[ClassWithProcedure].[Method];
GO

This will allow you to put different objects in different schemas

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