如何检查 tsqlconnection 是否打开?
登录失败后:
mytsqlconnection->Open();
if(mytsqlconnection->ConnectionState == csStateOpen)
{
...
}
“if”返回 true。如何检查连接是否真正打开?我是否必须执行查询并捕获异常?提前致谢。
弗朗西斯科
after an unsuccesfull login:
mytsqlconnection->Open();
if(mytsqlconnection->ConnectionState == csStateOpen)
{
...
}
the "if" returns true. How can I check if the connection is really open? Do I have to execute a query and catch the exception? Thanks in advance.
Francesco
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果登录失败,
Open()
应该引发异常。除非 Open() 成功建立与数据库的连接且没有错误,否则ConnectionState
属性不会设置为csStateOpen
。If the login fails,
Open()
should be raising an exception. TheConnectionState
property is not set tocsStateOpen
unless Open() is successful in establishing a connection to the DB without error.这是司机的问题。我使用了 cppbuilder6 附带的 dbexpora.dll(右键单击 dbexpora.dll 没有提供有关版本的信息)。我更改驱动程序,一切正常:Open() 引发异常,ConnectionState 按预期设置。谢谢。
弗朗西斯科
It was a matter of driver. I used the dbexpora.dll that came with cppbuilder6 (right-click on dbexpora.dll give no info about version). I change driver and everything works fine: Open() raise the exception, ConnectionState is set as expected. Thankyou.
Francesco