How can I best use VBA in Access or Excel to test an ODBC connection?

Given a pre-configured ODBC System DSN, I'd like to write a function that gracefully **tests** that connection using VBA. Private Function TestConnection(ByVal dsnName As String) As Boolean ' What goes here?? ' End Function Edit: To clarify, the System DSNs are pointing to external SQL Server 2005 databases, with Windows NT authentication. One approach I've tried is to send some random query to the target database and catch the error. If the query works, return true. If there's an error then return false. This works just fine but it feels...kludgy. Is there a more elegant way, especially one that doesn't rely on *On Error Goto* ? Note: It's a legacy Access 2000 database I'm working on, so any solution can't have any Access 2007 or 2003 dependencies. I'd like to make it generic to VBA, but if there's a simple way in Access that's fine too. Much obliged for any advice.
I put two possible answers here: stackoverflow.com/questions/35281342/test-sql-server-connection/…

以上就是How can I best use VBA in Access or Excel to test an ODBC connection?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » excel

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏