如何使用ASP.NET从WS 2012和IIS 8运行访问 [英] How do I run access from a WS 2012 and IIS 8 with ASP.NET

查看:108
本文介绍了如何使用ASP.NET从WS 2012和IIS 8运行访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过漫长的一天与服务器的斗争,我可以通过服务器2012在客户端计算机上运行我的.aspx页面。



现在一个新问题,我的页面没有响应服务器上保存的数据库MS ACCESS。



没有错误...并且页面没有响应事件的下拉列表。



它在开发者机器上工作正常...



任何人都请帮忙。



谢谢



我的尝试:



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.

推荐答案

您可以使用访问数据库,但不能运行应用程序本身。这是我用来在Access数据库中获取/放置数据的静态类。如果这不是您所需要的,那么您将不得不改进您的问题。



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.

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;
        }
    }
}


在项目中添加数据库,它确实解决了我的问题。



但我对此并不满意......



必须有能力从任何一个访问数据库服务器中的文件夹。



如果您同意,请回复。
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.


这篇关于如何使用ASP.NET从WS 2012和IIS 8运行访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆