Solved

Error databinding when multiple user access site

Posted on 2011-09-29
6
245 Views
Last Modified: 2012-05-12
I have a website developed in VS2010 that in published on a production server and  uses a static instance of a connection string.  When multiple users try to use the site at the same time they recieve Data Binding errors.  It's like the wrong data is being returned or that the gridview is trying to bind to the wrong result set.  I can not reproduce the errors on my local machine.  I have checked the stored procedures and know that they return the correct column names.  If you let the error sit for a couple minutes or restart the program the error will disappear.  Here is how the connection string is written:
public class DBCadView
{
      public DBCadView(string connectionString)
      {
            _Connection = new SqlConnection(connectionString);
        _DataAdapter = new SqlDataAdapter();
      }
    public static DBCadView Connection
    {
        get
        {
            if (_Instance == null)
            {
                _Instance = new DBCadView(ConfigurationManager.ConnectionStrings["PatternShop10"].ConnectionString);**(set in the webconfig)
            }
            return _Instance;
        }
    }
    public DataTable getCadView()
    {
        try
        {
            _Connection.Open();
            SqlCommand command = new SqlCommand("spps_getCadViewData", _Connection);
            command.CommandType = CommandType.StoredProcedure;
            _DataAdapter.SelectCommand = command;
            DataTable result = new DataTable();
            result.Clear();
            _DataAdapter.Fill(result);
            _Connection.Close();
            return result;

        }
        catch
        {
            _Connection.Close();
            return null;
        }
    }
       private SqlDataAdapter _DataAdapter;
    private SqlConnection _Connection;
    private static DBCadView _Instance;
}

any help or suggestion anyone may have to eliminate these errors would be greatly appreciated.  Thank you for your time
0
Comment
Question by:hscast
  • 3
  • 2
6 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 36817170
What is the exact type of Exception and exact message they receive?

-----

You do not need to Open and Close the connection when you use Fill. Fill will do it automatically for you, and will take care of doing it before triggering an Exception it it happens. You need to Open and Close with a DataReader, when executing a Command object directly or when working in transaction mode. But not with Fill or FillSchema when you are executing them outside of a Transaction.

Since, by default, you can have only one operation running at a time on a connection instance, this also prevents problems should the connection not close properly somewhere.

It is also suggested to use a local variable for the Connection. As long as you use the exact same ConnectionString all the time, the connection pooling built into the SqlConnection object will manage the connection in a better way than you can.

By using the built-in mechanisms of the SqlClient class, you have less chances of a Connection keeping a lock on a table somewhere.

It could correct your problem.
0
 

Author Comment

by:hscast
ID: 36817569
1.  DataBinding: 'System.Data.DataRowView' does not contain a property with the name "some column name
2.  Column "some column name" does not belong to table


We are using a link server.  Some of the data is located on a 2000 server and some is located on a 2008 server
0
 
LVL 4

Expert Comment

by:theHollow
ID: 36817607
Hello
How does your connection string look like?
It may be that there are some segment in the connection string that handle the locking problem.
It may also be good to take a look at the Stored Procedure that you get data from. Maybe it could need some kind of tuning?

You may also create the command from the connection instead of with the "new" keyword.
Example :
SqlCommand command = _Connection.CreateCommand();

May I see the exception that you get?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:hscast
ID: 36817671
Connection String from the web config - <add name="PatternShop10" connectionString="data source=SOYUZ;persist security info=False;user id=userid;password=pword;initial catalog=PatternShop;packet size=4096" />

error msg - DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'fdesc'.
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.Web.HttpException: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'fdesc'.

Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[HttpException (0x80004005): DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'fdesc'.]
   System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName) +8688109
   System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName, String format) +8
   System.Web.UI.WebControls.ListControl.PerformDataBinding(IEnumerable dataSource) +349
   System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +109
   System.Web.UI.WebControls.ListControl.PerformSelect() +34
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
   Websites_RushList_SampleShts_RushListDefault.LoadSearch() +430
   Websites_RushList_SampleShts_RushListDefault.Page_Load(Object sender, EventArgs e) +36
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +91
   System.Web.UI.Control.LoadRecursive() +74
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207


0
 
LVL 40
ID: 36818994
DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'fdesc'.

There is a control in the page that set to display the value of a field "fdesc" and this field is not part of the data fetched from the database by the spps_getCadViewData stored procedure.

You either have an extra control that is useless in the page, or the field "fdesc" was not specifier in the SQL command or stored procedure that is executed when you retrieve the data.

If the information is needed, look at the code in the stored procedure, or ask somebody to do it if you do not have access to it. If the field fdesc is not there, add it to the procedure. Or check that it is not mispelled, either in the procedure or in the part of the application where the binding is defined. The two need to match for binding to work.
0
 

Author Closing Comment

by:hscast
ID: 36891680
Ended up setting all the connections local and it works now, Thank you very much for your time
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now