After adding 8-9 products in basket, my database partially locks up

0

I would like to preface this by saying I never actually worked with Microsoft Database and ASP.NET. I got this project to fix, but I am not exactly familiar with the way it works.

So the site has a simple custom made webshop, without user registration. For every user, an individual key is being generated which lasts for a short while (couple of minutes) and its used to differentiate between different users and their baskets, a session key basically. Every time a user adds a product to a basket, a new database connection is open and the database stays open, but its still accessible to other users, so no problems on that part.

The user has the option to add products to the basket and this works perfectly. The issue comes if the user adds too many items to basket. Too many being around 8-9 products, after which the site returns [OleDbException (0x80004005): Unspecified error].

[OleDbException (0x80004005): Unspecified error]
System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) +966653
System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) +86
System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) +29
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +4911420
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117
System.Data.OleDb.OleDbConnection.Open() +40
piDataSloj.cDataSloj.DajDataReader(String mSq) +224
LucLib.cStavka.Load() +216
Lucel.Proizvodi.ibUKos_Click(Object sender, CommandEventArgs e) +1519
System.Web.UI.WebControls.CommandEventHandler.Invoke(Object sender, CommandEventArgs e) +0
System.Web.UI.WebControls.ImageButton.OnCommand(CommandEventArgs e) +8842310
System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +176
System.Web.UI.WebControls.ImageButton.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) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

Opening the basket, the total price is still shown, but all of the added products are no longer showing up. Any user, trying to open the store will get the same exception above, until the session key expires. So obviously nothing can be loaded from database after the exception happens.

So my question is, what could be the possible cause for this behavior? Basically, the same methods being called to add products work perfectly fine for X amount of times, then at some point, something goes wrong and it all hangs. Is it possible that somewhere in the code, the connection to database isn't being closed properly, so after 8 open connections, there's too many and the whole thing hangs? That's the only thing I can think of for the time being.

using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.UI;

namespace piDataSloj
{
    /// <summary>
    /// Objekti za pristup bazi
    /// </summary>
    public class cDataSloj : System.Web.UI.Page
    {
        private string sDbs = ConfigurationSettings.AppSettings["dbLuc"].ToString();
        private string sDb; 
        private OleDbConnection cDb;
        private OleDbCommand cmd;
        private string returnedString;

        #region " DajDataReader, DajScalar, DajNonQuery, DajDataTable metode "

        public OleDbDataReader DajDataReader(string mSq)
        {
            sDb = "Provider=Microsoft.Jet.OleDb.4.0; Data Source="+ Server.MapPath(sDbs);
            cDb = new OleDbConnection(sDb);
            cmd = new OleDbCommand(mSq, cDb);
            cDb.Open();
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }

        public string DajScalar(string mSq)
        {
            sDb = "Provider=Microsoft.Jet.OleDb.4.0; Data Source="+ Server.MapPath(sDbs);
            cDb = new OleDbConnection(sDb);
            cmd = new OleDbCommand(mSq, cDb);
            cDb.Open();
            try
            {
                returnedString =  cmd.ExecuteScalar().ToString();
            }
            catch
            {
                returnedString = string.Empty;
            }
            finally 
            {
                cDb.Close();
            }

            return returnedString;
        }

        public string DajNonQuery(string mSq)
        {
            sDb = "Provider=Microsoft.Jet.OleDb.4.0; Data Source="+ Server.MapPath(sDbs);
            cDb = new OleDbConnection(sDb);
            cmd = new OleDbCommand(mSq, cDb);
            cDb.Open();
            returnedString =  cmd.ExecuteNonQuery().ToString();
            cDb.Close();

            return returnedString;
        }

        public DataTable DajDataTable(string mSq)
        {
            sDb = "Provider=Microsoft.Jet.OleDb.4.0; Data Source="+ Server.MapPath(sDbs);
            cmd = new OleDbCommand();
            cDb = new OleDbConnection(sDb);
            OleDbDataAdapter da = new OleDbDataAdapter(mSq, cDb);
            DataTable dt = new DataTable();
            da.Fill(dt);
            da.Dispose();

            return dt;
        }

        #endregion

        #region " Dispose metoda "

        public void Zatvori()
        {
            cmd.Dispose(); 
            if (cDb.State.ToString() == "Open") { cDb.Close(); }
            cDb.Dispose();
        }

        #endregion
    }

}
asp.net
oledb
asked on Stack Overflow Nov 5, 2018 by DSofa • edited Nov 6, 2018 by DSofa

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0