none
MS Database not responding properly

    Question

  • I've created a database in MS-SQL and used it in my application.
    But sometimes it doesn't responds randomly and throws an exception System.Data.DataRowView' does not contain a property with the name 'Service_Name' while the column is in my table.
    Later on I've been dropped that DB and again created a new DB with new name but the problem remain persist.
    But this issue has not been occurred with the other existing DBs.

    I'm using this connection string:
    <add name="testCon" connectionString="Data Source=Comp1;Initial Catalog=TestDB;Persist Security Info=True;User ID=test;Password=test;" providerName="System.Data.SqlClient"/>

    and using this command on code behind
    "Select [Id], [Service_Name] from Table_Name"
    By using this command I'm filling a Drop Down-List and above prob raises.

    This works properly on SQL but occurred at front-end

    Please provide some proper solution ASAP.
    Thanks in advance.

    Tuesday, August 07, 2012 9:07 AM

All replies

  • Can you provide the code example how you access the ID property or how it is used in DropDownList?

    First of all have you double checked that you don't have typos? That is the most common reason, so check the cases where you have the column name for example in DataTextField or DataValueField names are ones.


    • Edited by MasaSam Tuesday, August 07, 2012 6:13 PM
    Tuesday, August 07, 2012 6:12 PM
  • Hi MasaSam,

    here is the code..

    SqlDataAdapter da = new SqlDataAdapter("select t.id, t.service_name from dbo.[Table_Name] t", testCon);
    DataTable dtt = new DataTable();
    da.Fill(dtt);
    if (dtt.Rows.Count > 0)
    {
      ddl1_sel.DataSource = dtt.DefaultView;
      ddl1_sel.DataTextField = "service_name";
      ddl1_sel.DataValueField = "id";
      ddl1_sel.DataBind();
      ddl1_sel.Items.Insert(0, new ListItem("Select Service", "0"));
    }

    and the exact error is:

    DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'service_name'. Object reference not set to an instance of an object.

    Thursday, August 09, 2012 6:53 AM
  • Your SQL in orginal question is "Select Id from Table_Name", so it does not contain "service_name". It should be "Select id, service_name from Table_Name".

    Friday, August 10, 2012 5:21 AM
  • Hi MasaSam,

    here is the code..

    SqlDataAdapter da = new SqlDataAdapter("select t.id, t.service_name from dbo.[Table_Name] t", testCon);
    DataTable dtt = new DataTable();
    da.Fill(dtt);
    if (dtt.Rows.Count > 0)
    {
      ddl1_sel.DataSource = dtt.DefaultView;
      ddl1_sel.DataTextField = "service_name";
      ddl1_sel.DataValueField = "id";
      ddl1_sel.DataBind();
      ddl1_sel.Items.Insert(0, new ListItem("Select Service", "0"));
    }

    and the exact error is:

    DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'service_name'. Object reference not set to an instance of an object.

    Hi Prashant,

    The code seems fine.

    Does the issue happened very time when you run this code?

    Have you check the dtt.DefaultView during debug?

    Could you please share a demo to help us to reproduce this issue?

    Best Regards,


    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us

    Friday, August 10, 2012 9:52 AM
    Moderator
  • @MasaSam:

    I've given the sample code in reply and also edited the question.

    Please don't stick with such mistakes from my side because I've reviewed the code several times

    including syntax and logical errors.

    One more thing which I would like to share you that I've hosted a replica of same Data Base on other server and its working fine.

    It works fine at localhost but the prob arises on live server in random manner, means database responds good all the time but suddenly the exception starts occurring for approx 25-30 min and after this duration it again start working properly.

    I've debug the code on live server too but no problem were found.

    The situation is very ridiculous and unpredictable.

    Saturday, August 11, 2012 6:28 AM
  • It seems that it might be some intermittent network or database server problems, although I don't see the correlation between those kinds of probelems and the error you're getting.

    The best you can do is try/catch around the code and have some error message show up in your dropdown instead of the valid items. Once the intermittent problem goes away, your app will start filling the dropdown again.


    ~~Bonnie Berent DeWitt [C# MVP]

    geek-goddess-bonnie.blogspot.com

    Saturday, August 11, 2012 10:48 PM
  • Hi BonnieB:

    I've already made the code in several try/catch blocks, and also wrote the exception occurred with this post.

    As you told,"it might be intermittent network or database server problems." That may be possible but what is that its quite undetectable.

    Situation is very ridiculous and unpredictable.

    Monday, August 13, 2012 6:45 AM
  • Hi Prashant,

    I think you should record the time that throw the exception and check then the event viewer. This may give some clues about why this happened.

    Best Regards,


    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us

    Monday, August 13, 2012 7:29 AM
    Moderator
  • ... and also wrote the exception occurred with this post.

    Yes, and that's why I said that "...I don't see the correlation between those kinds of problems and the error you're getting". In other words, your error: "DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'service_name'. Object reference not set to an instance of an object." doesn't seem to "go with" intermittent network or database server problems. I'd think you'd get a different, database-related error when you try to .Fill() your DataTable.

    However, Bob has a good suggestion ... check the Event Log (both on your local machine and on the database server) and see if there are any entries that might shed some light on any network or server issues.


    ~~Bonnie Berent DeWitt [C# MVP]

    geek-goddess-bonnie.blogspot.com

    Monday, August 13, 2012 3:36 PM