VB6 支持 SQL SMO 和 .Net 2.0
我们正在尝试在基于 COM+ 的应用程序中从使用 SQL DMO 转向使用 SMO,因为我们正在放弃对 SQL Server 2000 的支持,并在 SQL Server 2005 之外添加对 SQL Server 2008 的支持。
我一直在阅读相关内容,发现此微软论坛上的这个特殊俏皮话:
“SMO仅在 VB/C#.Net 2005 中受支持。它需要 .Net 2.0 框架,而 VB/VC 6 中不提供该框架。”
这是真的吗? 谷歌搜索一般和谷歌搜索 stackoverflow 并没有给出明确的答案。
是否可以使用VB6实现SQL SMO?
编辑:我使用 COM 包装器来解决这个问题...请查看下面我的答案以了解更多详细信息。
We are trying to move from using SQL DMO to SMO in our COM+ based application, as we are dropping support for SQL Server 2000 and adding support for SQL Server 2008 in addition to SQL Server 2005.
I have been reading around on this, and found this particular quip on this microsoft forum:
"SMO is only supported in VB/C#.Net 2005. It requires the .Net 2.0 Framework, which isn't available in VB/VC 6."
Is it true? Googling in general and googling stackoverflow did not throw up and definitive answers.
Is it possible to implement SQL SMO using VB6?
Edit: I used a COM Wrapper to get around this... check out my answer below for some more details.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
好吧,我想出了如何做到这一点。
问题是 VB6 没有 .Net 2.0 支持,因此我们不能将 SMO 与 VB6 一起使用。
为了解决这个问题,我用 C# 编写了一个 COM 包装器,它使用 SMO 并(大部分)与我想要从 VB 应用程序中获得的功能进行一对一映射。
基本上,创建一个 C# 项目,根据需要添加 SMO 引用,在类声明上方添加以下行以使其 COM 可见:
在项目属性的“构建”部分中,确保“注册 COM 互操作”框已检查。 编译并导入 VB6 应用程序,您就可以开始工作了!
与尝试将任何两个不同的系统整合在一起的情况一样,您需要对 VB6 应用程序和 C# 包装器之间传递的内容进行一些操作...但这并不太难。
如果您需要更多信息/详细信息,请发表评论。
Okay I figured out how to do this.
The problem was that VB6 has no .Net 2.0 support and hence we cannot use SMO with VB6.
To get around that, I wrote a COM wrapper in C# which uses SMO and maps (mostly) one-to-one with the kind of functionality I want from from my VB app.
Basically, Create a C# project, add the SMO references as needed, add the following lines above the class declaration to make it COM visible:
In the project properties, in the "Build" section, make sure the "Register For COM Interop" box is checked. Compile and import into the VB6 app and you are in business!!
As is the case with trying to hammer any two different systems together, there will be some manipulations you will need to do with what you pass between the VB6 app and the C# Wrapper... but its not too hard.
Please comment if you need any more information/details.
我不知道有什么方法可以通过 VB6 访问 SMO。 我同意 G Mastros 关于使用 COM/Interop 方法直接实现 .NET 代码的观点。
可以考虑的另一种选择是,您可以使用 Powershell,执行一个可以完成 .NET SMO 工作的脚本。 您仍然需要 .NET 框架(显然还有 Powershell),但它可以完成工作。 您的脚本可以采用凭据、数据库名称、备份类型等参数。
我在拥有 SQL Express(没有用于备份的 SQL 代理,如 MSDE)的客户端上经常实现这一点。 我连接了一个调用脚本并管理备份的计划任务。
如果有帮助的话,这里有一个脚本——大部分是偷来的,但我对其进行了一些修改:
它可以进行完整备份、差异备份和事务备份,并根据日期和时间对每个结果文件进行唯一命名,删除所有早于一定数量的文件。天。
调用它的语法是:
so...
要在任务计划程序中进行计划,请传入:
I don't know of a way you can get to SMO via VB6. I'd agree with G Mastros about doing a COM/Interop approach to implement .NET code directly.
An alternative to consider is that you could shell out to Powershell, executing a script that would do your .NET SMO work. You still have the pre-requisite of requiring the .NET framework (and Powershell obviously), but it would get the job done. Your script could take parameters for credentials, database name, backup type, etc.
I implement this a lot at clients who have SQL Express (no SQL Agent for backups, like MSDE). I hook up a scheduled task which invokes the script and manages their backups.
If helpful, here is a script -- largely stolen but I have modified it somewhat:
It can do full, differential, and transactional backups and uniquely names each resulting file based on the date and time, deleting all files older than a certain number of days.
The syntax to call it is:
so...
To Schedule in Task Scheduler, pass in:
谢谢你的帖子。 它帮助我理解有一个解决方案可以使用 COM Wrapper 从 VB6 中使用 SQLSMO。 我按照您详细说明的步骤操作,但我的解决方案不起作用。 我基本上是这样做的:
使用 System.Text;
使用 System.Runtime.InteropServices;
命名空间 WrapperCOM
{
}
我还为 SQLSMO 添加了以下引用:
•Microsoft.SqlServer.ConnectionInfo.dll
•Microsoft.SqlServer.Smo.dll
•Microsoft.SqlServer.Management.Sdk.Sfc.dll
•Microsoft.SqlServer.SqlEnum.dll
最后当我导入 .tlb 文件并创建如下对象后运行 VB6 -
CreateObject("COMWrapper.Class1"),失败。 它给出“运行时错误...”
请告知我在这里缺少什么...
Thanks for your post. It helps me to understand that there is a solution to use SQLSMO from VB6 using COM Wrapper. I followed the steps you detailed, but my solution doesn't work . I am doing this basically:
using System.Text;
using System.Runtime.InteropServices;
namespace WrapperCOM
{
}
I also added the following references for SQLSMO:
•Microsoft.SqlServer.ConnectionInfo.dll
•Microsoft.SqlServer.Smo.dll
•Microsoft.SqlServer.Management.Sdk.Sfc.dll
•Microsoft.SqlServer.SqlEnum.dll
Finally when I run the VB6 after importing the .tlb file and creating an object like this -
CreateObject("COMWrapper.Class1"), It fails. It gives "RunTime Error..."
Pls advise as to what's that I am missing here...
我还没有尝试过,但您可能可以编写 vb.net 代码来与 SQL SMO 交互,然后为 vb.net 代码编写 com 包装器。 当然,您仍然需要 .net 框架才能使用它。
相反,我建议您放弃 SQL DMO 和 SQL SMO。 使用 DMO 或 SMO 所做的任何事情都可以在没有它的情况下完成。 当然,这并不容易,但是通过谷歌搜索替换代码(使用直接的 T-SQL 而不是 SQL DMO)将为您提供所需的答案。
I haven't tried it, but you could probably write vb.net code to interact with SQL SMO, and then write a com wrapper for the vb.net code. Of course, you'll still need to .net framework to use it.
Instead, I would suggest that you migrate away from SQL DMO and SQL SMO. Anything you do with DMO or SMO can be done without it. Of course, it won't be easy, but googling for replacement code (using straight T-SQL instead of SQL DMO) will provide you the answers you need.