我正在为正在处理的应用程序创建登录表单。我已经设置了应用程序以正确连接到数据库,并在数据库上也运行存储过程和查询。
但是我不确定如何从数据库向我的VB.Net应用程序发送消息。现在,我基本上有两种方法可以为数据库执行代码:
Public Function ExecuteCMD(ByRef CMD As SqlCommand) As DataTable
Dim DS As New DataSet()
Try
OpenDBConnection()
CMD.Connection = DB_CONNECTION
If CMD.CommandText.Contains(" ") Then
CMD.CommandType = CommandType.Text
Else
CMD.CommandType = CommandType.StoredProcedure
End If
Dim adapter As New SqlDataAdapter(CMD)
adapter.SelectCommand.CommandTimeout = 300
adapter.Fill(DS)
Catch ex As Exception
Throw New Exception("Database Error: " & ex.Message)
Finally
CloseDBConnection()
End Try
Return DS.Tables(0)
End Function
Public Function ExecuteCMDWithReturnValue(ByRef CMD As SqlCommand) As Boolean
Try
OpenDBConnection()
CMD.Connection = DB_CONNECTION
CMD.Parameters.Add("@ret", SqlDbType.Int).Direction = ParameterDirection.ReturnValue
CMD.CommandType = CommandType.StoredProcedure
CMD.ExecuteNonQuery()
Dim result As Object = CMD.Parameters("@ret").Value
Return If(Convert.ToInt32(result) = 1, False, True)
Catch ex As Exception
Throw New Exception("Database Error: " & ex.Message)
Return False
Finally
CloseDBConnection()
End Try
End Function
这些功能确实可以正常工作,但对于错误处理来说却是可怕的。
例如,我希望能够设置存储过程以登录到应用程序以返回“找不到用户名”或“密码错误”消息,以便我可以向用户确切显示问题所在是,而不是只返回一般的“登录信息不正确”消息,而是仅在进行登录或不登录时返回true或false。
很不幸,我不知道到底该怎么做。我不知道要在SQL Server端设置什么以使其在过程中吐出消息,我也不知道在VB.Net中接收这些消息很热。
答案 0 :(得分:1)
您可以在VB中验证您的用户权限。我认为告诉用户密码或用户名是否错误(或两者都不正确)不是一个好主意。如果此数据受密码保护,则应防止恶意登录。这将有助于黑客知道出了什么问题。
<div id="container">
<div class="section">
<div class="header">Heading</div>
<div class="wrapper">
<p>Large Text</p>
</div>
</div>
</div>
html, body {
margin: 0px;
padding: 0px;
height: 100%;
}
#container {
display: flex;
flex-direction: column;
height: 100%;
}
.section {
flex-grow: 1;
display: flex;
flex-direction: column;
min-height: 0;
}
.header {
height: 64px;
background-color: lightblue;
flex-shrink: 0;
}
.wrapper {
flex-grow: 1;
overflow: auto;
min-height: 100%;
}
当然,密码是用盐散列存储的。