Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
After a long day struggle with server i'm able to run my .aspx pages via server 2012 on client machines.

Now a new problem, my page is not responding to the database MS ACCESS saved on server.

No error ... and page is not responding on event by dropdown.

Its working fine on developer machine...

Anyone please help.

Thanks

What I have tried:

I did make it compatible with 32bit, but all in vain.

here is the code
query = "select DISTINCT PLAN from FEE where course='" + ddlProgram.DataValueField + "' and acd_session='2017_18'";

        using (OleDbConnection connection = new OleDbConnection(cnstr))
        {
            OleDbCommand command = new OleDbCommand(query, connection);
            connection.Open();
            OleDbDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
                ddlCoursePlan.Items.Add(reader.GetValue(0).ToString());
            }
        }


Now on change in drop down there is no action.

While things are working fine at the time of development.
Posted
Updated 3-Jan-17 0:11am
v2
Comments
Richard MacCutchan 31-Dec-16 8:25am    
Please provide proper details. No one here can guess what your code is doing.

You can use an access database, but not "run" the application itself. Here's a static class I use to get/put data in an Access database. If this isn't what you need, you're going to have to improve your question.

C#
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Text;

namespace BODCommon
{
    /// <summary>
    /// 
    /// </summary>
    public static class AccessDBObject
    {
        /// <summary>
        /// Gets or sets the connection string.
        /// </summary>
        public static string ConnectionString { get; set; }

        /// <summary>
        /// Initializes the <see cref="AccessDBObject"/> class.
        /// </summary>
        static AccessDBObject()
        {
        }

        /// <summary>
        /// Gets the data using a plain query string.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <returns></returns>
        public static DataTable GetData(string query)
        {
            DataTable result = new DataTable();
            try
            {
                OleDbConnection conn = null;
                OleDbDataAdapter cmd = null;
                using (conn = new OleDbConnection(AccessDBObject.ConnectionString))
                {
                    conn.Open();
                    using (cmd = new OleDbDataAdapter(query, conn))
                    {
                        cmd.Fill(result);
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex != null) {}
            }
            return result;
        }

        /// <summary>
        /// Gets the data using a list of parameters (as opposed to a plain query string)
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="parameters">The parameters.</param>
        /// <returns></returns>
        public static DataTable GetData(string query, List<OleDbParameter> parameters)
        {
            DataTable result = new DataTable();
            try
            {
                OleDbConnection conn   = null;
                OleDbCommand    cmd    = null;
                OleDbDataReader reader = null;
                using (conn = new OleDbConnection(AccessDBObject.ConnectionString))
                {
                    conn.Open();
                    using (cmd = new OleDbCommand(query, conn))
                    {
                        if (parameters != null)
                        {
                            foreach(OleDbParameter param in parameters)
                            {
                                cmd.Parameters.Add(param);
                            }
                        }
                        reader = cmd.ExecuteReader();
                        result.Load(reader);
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex != null) {}
            }
            return result;
        }

        /// <summary>
        /// Sets the data.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="parameters">The parameters.</param>
        /// <returns></returns>
        public static int SetData(string query, List<OleDbParameter> parameters = null)
        {
            int recordsAffected = 0;
            try
            {
                OleDbConnection conn = null;
                OleDbCommand cmd = null;
                using (conn = new OleDbConnection(AccessDBObject.ConnectionString))
                {
                    conn.Open();
                    using (cmd = new OleDbCommand(query, conn))
                    {
                        if (parameters != null)
                        {
                            foreach(OleDbParameter param in parameters)
                            {
                                cmd.Parameters.Add(param);
                            }
                        }
                        recordsAffected = cmd.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex != null) {}
            }
            return recordsAffected;
        }
    }
}
 
Share this answer
 
add database in project itself and it did solved my problem.

but I'm not happy with this...

One must have the power to access database from any of the folder in server.

Reply if you agree with me.
 
Share this answer
 
Comments
Dave Kreskowiak 3-Jan-17 7:13am    
If you didn't add the database to the project it would not have been deployed if you used the Publish feature in Visual Studio. Your database would not have been copied to the server. No database on the server and your code fails.

Now, being able to use the database from "any folder" in your ASP.NET app depends on the connection string you're using and if it points to the correct location of the Access file. If it's using a relative path, it may or may not work correctly in an ASP.NET app.

If you want to get to the database "from anywhere" you REALLY need to use a REAL database engine, such as SQL Server. Access is a file-based DESKTOP database, not meant for server work.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900