我正在创建一个应用程序,我创建了一个loding屏幕,用于检查将在应用程序中使用的数据库的可用性,如果与数据库的连接出现在kk然后加载表单将打开登录表单或者我想要那个表单显示错误消息,说明网络连接问题。
你能给我一些关于如何解决这个问题的想法吗?
I am Creating a app and I though of creating a loding screen with which will check the availablity of database which will use in the application if the connection to database appers to kk then then loading form will open the login form or orelse i want that form to display a error message saying network connectivity issue.
can you give give ideas on how can i work that out ?
最满意答案
我的建议是在检查连接时不显示加载屏幕,原因有两个:
因为通常数据库连接检查的速度非常快,以至于用户甚至看不到加载屏幕,或只看到它的闪烁,在这种情况下,他会对发生的事情感到困惑。在我看来,这不是一个很好的做法。 如果发生故障,我宁愿显示一个消息框。 灵感来自SULFIKAR的答案:
Sqlconnection con=new SqlConnection(); con.ConectionString="myconnectionstring"; try { if(con.State==ConnectionState.Open) { con.Close(); } con.Open(); //Everything ok -> continue normally } catch(Exception ex) { MessageBox.Show("Database connection not available..."));//do something in case of error : exit application, log ex.Message, etc }My suggestion is not to show a loading screen while checking the connection, for 2 reasons :
Because usually the database connection check is done so fast that the user would not even see the loading screen, or only see a flicker of it, in which case he would be confused as to what is happening.In my opinion it's not a very good practice. I would rather show a messagebox if a failure would happen. Inspired by the answer of SULFIKAR:
Sqlconnection con=new SqlConnection(); con.ConectionString="myconnectionstring"; try { if(con.State==ConnectionState.Open) { con.Close(); } con.Open(); //Everything ok -> continue normally } catch(Exception ex) { MessageBox.Show("Database connection not available..."));//do something in case of error : exit application, log ex.Message, etc }更多推荐
发布评论