添加 iTextSharp dll 以与 CLR 存储过程一起使用

发布于 2024-09-13 18:15:27 字数 312 浏览 4 评论 0原文

有没有人有幸为 iTextSharp 创建一个与 CLR 存储过程一起使用的程序集?我整个下午都在努力,但没有得到任何结果。 SQL Management Studio 说我需要先注册 system.drawing (不能是新版本,必须是旧版本),但是当我尝试运行 create it for safe 和 unsafe 时,它​​给我带来了问题。

所以我只是想知道是否有人有幸设置 iTextSharp 通过 CLR SPROCS 工作?我想这样做的原因是因为这样我就能够更轻松地传递参数并生成报告(CLR SPROC 保存标准静态内容,而参数可以控制动态内容)

感谢您的帮助

Has anyone had any luck creating an assembly for iTextSharp for use with CLR Stored procedures? I've been trying all afternoon and have not been able to get any results. SQL management studio is saying I need to register system.drawing first (can't be the new version, has to be the old version no less) but it gives me issues when I try to run create it for safe and unsafe.

So I'm just wondering if anyone has had any luck with setting up iTextSharp to work via CLR SPROCS? The reason I want to do this is because then I'd be able to pass parameters and generate reports much easier (CLR SPROC holds the standard static stuff while parameters could control dynamic stuff)

Thanks for any help

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

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

发布评论

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

评论(2

对你的占有欲 2024-09-20 18:15:27

在服务器上注册这些程序集:

CREATE ASSEMBLY [System.Drawing] FROM
  'C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll'
  WITH PERMISSION_SET = UNSAFE

CREATE ASSEMBLY [System.Windows.Forms] FROM
  'C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll'
  WITH PERMISSION_SET = UNSAFE

CREATE ASSEMBLY [itextsharp] FROM
  'C:\MY_CLR\itextsharp.dll'
  WITH PERMISSION_SET = UNSAFE

然后您可以在“添加引用”对话框(SQL Server 选项卡)中找到 itextsharp 的引用

它可以工作(VS2010、C#、SQLServer2005、itextsharp5.0)

Register these assemblies on the server:

CREATE ASSEMBLY [System.Drawing] FROM
  'C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll'
  WITH PERMISSION_SET = UNSAFE

CREATE ASSEMBLY [System.Windows.Forms] FROM
  'C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll'
  WITH PERMISSION_SET = UNSAFE

CREATE ASSEMBLY [itextsharp] FROM
  'C:\MY_CLR\itextsharp.dll'
  WITH PERMISSION_SET = UNSAFE

Then you can find refence for itextsharp in Add reference dialog (SQL Server tab)

It works (VS2010, C#, SQLServer2005, itextsharp5.0)

拥有 2024-09-20 18:15:27

正如其他答案所暗示的那样,您不需要需要System.Windows.Forms.dll
只需将这两个引用添加到您的 Visual Studio 项目中:

  1. System.Drawing.dll
  2. itextsharp.dll

确保您的项目引用了这两个 DLL。
然后在这 2 个引用的 DLL 的属性中,将“Model Aware”属性设置为“True
关于这个几乎没有记录的属性的某些内容将自动部署您引用的程序集。
输入图片此处描述

重建您的项目(请务必执行此操作,否则您可能会看到错误)并尝试部署。
它应该自动将这 2 个引用作为程序集添加到您的 SQL 数据库。
添加后,它至少足够聪明,不会在后续重新部署时删除并再次添加它们。

注意:执行此操作后,每次我尝试部署项目时都会失败。
我不知道为什么会这样,但我愿意忍受它(我正在使用 VS2013)。


警告:我遇到了这个可怕的错误:

ALTER ASSEMBLY 失败,因为引用的程序集将发生更改。引用的程序集列表必须保持不变。

如果发生这种情况,您需要删除整个程序集,因为有关部署的某些事情会导致程序集的一部分保持完整,并且不会更新外部引用,而是会给出此神秘/无用的错误。

我最终所做的就是删除 PreDeployScript.sql 中的所有依赖项程序集。
这样,我就可以避免在部署 SQL 程序集的任何服务器上(或在添加新引用时)出现此问题。

You do not need System.Windows.Forms.dll as the other answer suggests.
Just Add these 2 References to your Visual Studio Project:

  1. System.Drawing.dll
  2. itextsharp.dll

Make sure both of these DLL's are Referenced by your Project.
Then in the Properties of these 2 Referenced DLL's, set the "Model Aware" Property to "True"
Something about this barely-documented Property will auto-deploy your Referenced Assembly.
enter image description here

Rebuild your Project (make sure to do this or you may see an error) and try Deploying.
It should automatically add these 2 References as Assemblies to your SQL Database.
Once added, it is at least smart enough not to drop and add them again on subsequent re-deploys.

NOTE: After doing this, it fails every other time I try to Deploy my Project.
I don't know why that is, but I'm willing to put up with it (I'm using VS2013).


WARNING: I ran into this horrible error:

ALTER ASSEMBLY failed because the referenced assemblies would change. The referenced assembly list must remain the same.

If this happens, you need to drop the entire assembly, because something about the deployment causes part of the assembly to remain intact and does not update the External-References and instead gives this cryptic/unuseful error instead.

What I ended up doing was dropping all dependencies and the Assembly in my PreDeployScript.sql .
This way I avoid the issue on any Server I deploy my SQL Assembly to (or when I add new References).

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