如何为 App.Config 连接字符串显示登录失败消息框 [英] How to display a login failure messagebox for App.Config connection string

查看:20
本文介绍了如何为 App.Config 连接字符串显示登录失败消息框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下连接字符串并且能够登录到 SQL 2008 R2 Server.

I use the following connection string and am able to log into SQL 2008 R2 Server.

My.Settings.Item("CustomerConnectionString") = "Data Source=FAROOK-PC\SQLEXPRESS;Initial 
Catalog= '" & Me.ComboBox1.Text & "'; uid = '" & Me.Login1.Text & "'; pwd = '" & 
Me.Password1.Text & "'"

如何在登录失败时显示消息框.

How do I display a messagebox on login failure.

谢谢.

推荐答案

使用 Try Catch Block.如果连接失败,请在 catch 块中使用您的消息框.

use Try Catch Block. If connection fails use yor message box in catch block.

Dim sqlCnn As New SqlConnection
Dim connString as string = "Your Connection String"
Try
   sqlCnn = New SqlConnection(connString)
   sqlCnn.open()
Catch ex As SqlException
   MsgBox("Login Failed")

End Try

这篇关于如何为 App.Config 连接字符串显示登录失败消息框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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