1

Тема: ASP.NET

Виникла помилка під час роботи з проектом, при відображенні у браузері:
Server Error in '/' Application.

Invalid object name 'Student'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Invalid object name 'Student'.

Source Error:

The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

  <%@ Page Language="C#" Debug="true" %>

or:
2) Add the following section to the configuration file of your application:

<configuration>
   <system.web>
       <compilation debug="true"/>
   </system.web>
</configuration>

Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.

Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.

Stack Trace:

[SqlException (0x80131904): Invalid object name 'Student'.]
   System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +1753986
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5296058
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +558
   System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +1682
   System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +59
   System.Data.SqlClient.SqlDataReader.get_MetaData() +90
   System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +365
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite) +1379
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +175
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +53
   System.Data.SqlClient.SqlCommand.ExecuteScalar() +149
   Login.Button1_Click(Object sender, EventArgs e) +177
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9553178
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724

2 Востаннє редагувалося Bogdan (06.12.2014 23:33:48)

Re: ASP.NET

я зроблю уточнення:
1)при заповненні 1 і 2 поля, нажавши Логін повинна висвітлитися перд тим заполвнена база, під пароль та Id, але чомусь мені видає помилку(

Post's attachments

1.jpg 121.21 kb, 253 downloads since 2014-12-06 

3

Re: ASP.NET

Важко такк щось сказати, було би набагато простіше як би ви показали код цього методу.
Login.Button1_Click. І щіе мені не зовсім зрозуміло як ви працюєте з базою це ado.net ?

4 Востаннє редагувалося Bogdan (07.12.2014 15:36:07)

Re: ASP.NET

ось :

public partial class Login : System.Web.UI.Page
{
    private string strcon = WebConfigurationManager.ConnectionStrings["StudentConnectionString1"].ConnectionString;

    protected void Page_Load(object sender, EventArgs e)
    {
       if (!IsPostBack)
       {
           if(Request.Cookies["UName"] != null)
               TextBox1.Text=Request.Cookies["UName"].Value;
           if(Request.Cookies["PWD"] != null)
               TextBox2.Attributes["value"] = Request.Cookies["PWD"].Value;
           if(Request.Cookies["UName"] != null && Request.Cookies["PWD"] != null)
               CheckBox1.Checked = true;
       }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(strcon);
        SqlCommand cmd = new SqlCommand("Select StudName from Student where StudId=@sid and Password=@pw", con);
        cmd.Parameters.AddWithValue("@sid", TextBox1.Text);
        cmd.Parameters.AddWithValue("@pw", TextBox2.Text);
        con.Open();
        string name = Convert.ToString(cmd.ExecuteScalar());
        con.Close();
        if (String.IsNullOrEmpty(name))
            Label1.Text = "Sorry! Invalid Student ID or Password!";
        else
        {
            if (CheckBox1.Checked)
            {
                Response.Cookies["UName"].Value = TextBox1.Text;
                Response.Cookies["PWD"].Value = TextBox2.Text;
                Response.Cookies["UName"].Expires = DateTime.Now.AddMonths(2);
                Response.Cookies["PWD"].Expires = DateTime.Now.AddMonths(2);
            }
            Session.Add("studid", TextBox1.Text);
            Session.Add("studname", name);
            FormsAuthentication.RedirectFromLoginPage(name, false);

        }
    }
}

5 Востаннє редагувалося Bogdan (07.12.2014 17:52:53)

Re: ASP.NET

в неті знайшов таку ж  помилку, тільки нічого не розумію:
http://answerstop.org/question/229585/s … o-projects

6

Re: ASP.NET

Cкоріше за все в вас не має таблиці з назвою Student. Можливо вона називається Students.

7

Re: ASP.NET

змінити її ім'я неможливо. Якщо створити нову таку ж, то автоматично вона підключиться до проекту?

8

Re: ASP.NET

SqlCommand cmd = new SqlCommand("Select StudName from Student where StudId=@sid and Password=@pw", con);

Попробуйте тут змінити Student на Students. А вазагіто виберіть якусь програму для того щоб ви могли бачити структуру вашої бази даних і могли запускати квері. Якщо це ms sql  то management studio підійде і попробуйте спочатку в ній запускати всі ваші квері

Подякували: Bogdan1

9

Re: ASP.NET

дякую, я замінив так як Ви написали тепер працює, веливе спасибі