我正在尝试通过从我的数据库 UsersDB 中读取用户详细信息来通过登录表单对用户进行身份验证。在尝试读取时,我收到一个错误:无效的对象名称:UsersDB
将新用户添加到数据库时我没有收到任何错误,所以我不知道为什么会收到此错误。这是我得到的堆栈跟踪:
[SqlException (0x80131904): Invalid object name 'UsersDB'.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +388
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +810
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +4403
System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +82
System.Data.SqlClient.SqlDataReader.get_MetaData() +135
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +6666037
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite) +6667856
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +577
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +107
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +288
System.Data.SqlClient.SqlCommand.ExecuteReader() +302
AuthWebRole.Account.UserLogin.Buttonlogin_Click(Object sender, EventArgs e) in c:\Users\Tamara\Documents\Visual Studio 2012\Projects\TCWalletAzure\AuthWebRole\Account\UserLogin.aspx.cs:32
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +155
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3804
编辑:
查询如下:(我在我的代码中替换了我的用户名和密码)
string strcon = "Server=tcp:qemcclhlar.database.windows.net,1433;Database=UsersDB;User ID=[userid];Password=[mypassword];Trusted_Connection=False;Encrypt=True;Connection Timeout=30";
SqlConnection con = new SqlConnection(strcon);
SqlCommand com = new SqlCommand("CheckUser", con);
com.CommandType = CommandType.StoredProcedure;
SqlParameter user = new SqlParameter("username", UserName.Text);
SqlParameter pword = new SqlParameter("password", Password.Text);
com.Parameters.Add(user);
com.Parameters.Add(pword);
con.Open();
SqlDataReader rd = com.ExecuteReader();
if (rd.HasRows)
{
rd.Read();
LabelInfo.Text = "Login successful.";
}
else
{
LabelInfo.Text = "Invalid username or password.";
}
数据库架构:
数据库:带有表 UserTable 的 UsersDB