[英]Visual studio 2010 C# debugging MS Dataset
I am using MSDatasets to link to a server (on local network), method are as below: 我正在使用MSDatasets链接到服务器(在本地网络上),方法如下:
1) Right click the project -> add new item 1)右键单击项目->添加新项目
2) Select dataset and rename 2)选择数据集并重命名
3) Open server explorer and add new connection to server on local network 3)打开服务器资源管理器并向本地网络上的服务器添加新连接
4) Once connected to the local server, drag tables needed into the datasets 4)连接到本地服务器后,将所需的表拖到数据集中
5) the dataset/ table could be called from classes in the program 5)可以从程序中的类调用数据集/表
Everything worked fine. 一切正常。 But sometimes the server might be down for some reasons, and the program thus fail to connect and prompts a error message "A unhandle win32 exception occurred in program.exe......." and then quits the program itself.
但是有时由于某些原因服务器可能已关闭,因此程序无法连接,并提示错误消息“在program.exe中发生未处理的Win32异常........”,然后退出程序本身。
How can a prompt the user with a more user-friendly message (eg "sorry the server is down, please try again later") when the connection to the server fails? 当与服务器的连接失败时,如何提示用户更多用户友好的消息(例如“对不起服务器已关闭,请稍后重试”)?
Thanks! 谢谢!
The only time a DataSet object really connects to the server is when you call your Adapter's Update()
or Fill()
functions (assuming you're using typed approach only). 只有当您调用适配器的
Update()
或Fill()
函数(假设您仅使用类型化方法)时,DataSet对象才真正连接到服务器。 You could place those pieces inside try/catch blocks to achieve what you want. 您可以将这些片段放置在try / catch块中,以实现所需的功能。
If you are using drag-n-drop from Data Sources window, you should have these lines inside your Form's Load
event handler and navigation toolbar's SaveButton_Click
(or something like that) event handler. 如果要使用“数据源”窗口中的拖放功能,则应在窗体的
Load
事件处理程序和导航工具栏的SaveButton_Click
(或类似名称)事件处理程序中包含这些行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.