VBA数据层错误处理 [英] VBA data layer error handling

查看:145
本文介绍了VBA数据层错误处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些传统的Excel文件,对存储过程和数据库连接进行了大量调用,所有这些都以旧的方式与记录集完成。

I have some legacy Excel files with tons of calls to stored procedures and db connections all done in the old fashion with recordsets...

因为在VBA中没有try-catch的概念 - 最终像.NET那样有什么最佳实践可以应用到更加坚实的数据访问层吗?我想有一个很好的例子,说明如何打开连接,执行一个需要一些参数的存储过程,然后在任何情况下成功或错误,关闭连接和释放资源。

since in VBA there is no concept of try-catch-finally like in .NET is there any best practice to apply to have a bit more solid data access layer? I would like to have a nice example on how to open connection, execute a stored procedure which requires some parameters and then in any case of success or errors, close the connection and release resources.

推荐答案

我实际上正在使用不同的方法,我创建了一个.NET托管数据层,并将其导出为COM类,遵循以下说明:调用.NET从VBA 以这种方式我必须部署和注册COM程序集与excel文件,这有点痛苦我承认,但至少我可以以正确的方式处理数据访问,并使用C#,ADO.NET等...

I am actually using a different approach now, I created a .NET managed data layer and exported it as COM class, following the instructions here: Calling .NET from VBA in this way I have to deploy and register the COM assembly together with the excel file and it's a bit painful I admit, but at least I can handle data acces in a proper way and use C#, ADO.NET and so on...

这篇关于VBA数据层错误处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆