我现在有一个程序,凡是要读取数据的.ASPX浏览时都连接不上数据库
对这个语言稍有了解,但只是基础中的基础,请大哥大姐们说的傻瓜些好吗?谢谢啦.
下面是其中一个页面的CS文件代码,帮我看看.是不是还需要我配置些什么东西?与OFFICE有关吗?我系统是电脑公司版5.1的,只自带的WORD,EXCEL下面是代码帮忙看下,谢谢了.麻烦了.万分感谢..感激不尽..using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TjSystem.SCDD.UserAuth;
using TjSystem.DataInterface;
using System.Xml;public partial class leftmenu : System.Web.UI.Page
{
    public string[] FirstNode = new string[50];
    public string[] FirstNodeCode = new string[50];
    public int MaxFirstNode;
    public XmlDocument MyXmlDoc;
    public CFuncNodeAllowCfg MyFuncNodeAllowCfg;
    public TreeView MyTreeView;
    public string[] functionlink=new string[50];
    public int Menu1Count;
    public int MenuHeight;
    public int TreeHeight;
    protected void Page_Load(object sender, EventArgs e)
    {
        TreeNode[] node; //定义treeview节点
        ImageButton[] ButtonTree;
        int k;
        k = 40;
        ButtonTree = new ImageButton[k];
        node = new TreeNode[20];
        //
          
        //
        MenuHeight = 480; //整个menu的高度
        //调试用
       Session["username"] = "user1";       string[] image=new string[9];
       image[0] = "images/a.jpg";
       image[2] = "images/b.jpg";
       image[4] = "images/c.jpg";
       image[6] = "images/d.jpg";
      if (Session["username"] == null)
         {
             Response.Write("<script>self.parent.location.href='login.aspx';</script>");//进入主页
         }        else
        {
     
           
            string username;
            username = Session["username"].ToString();
            if (username != "")
            //创建目录类
            {                if (!IsPostBack)
                {                    //读功能授权数据库,获得一级目录
                    TjSystem.SCDD.UserAuth.CFuncNodeAllowCfgFactory MyFuncNodeAllowcfgFactory;//创建一个目录节点工程类
                    MyFuncNodeAllowcfgFactory = new CFuncNodeAllowCfgFactory();                    CReadCfgFile MyReadCfgFile = new CXmlReadCfgFile(this.Server.MapPath("config"));                    CDbServInfo MyDbServInfo = MyReadCfgFile.ReadDbServInfo();
                    int DbType = MyDbServInfo.m_iDbType;                    MyFuncNodeAllowCfg = MyFuncNodeAllowcfgFactory.BuildDataTable();
                    MyFuncNodeAllowCfg.SetDbServInfo(MyDbServInfo);                    int flag = MyFuncNodeAllowCfg.ConnectDb();                    MyXmlDoc = MyFuncNodeAllowCfg.GetFirstNodeInfoByUserName(username);
                    Session["MyXmlDoc"] = MyXmlDoc;                }
                else
                {                    MyXmlDoc = (System.Xml.XmlDocument)Session["MyXmlDoc"];
                }                System.Xml.XmlNode mynode;                if (MyXmlDoc == null)
                {
                    Response.Write("无法联接数据库!");
                }
                else
                {
                    mynode = MyXmlDoc.SelectSingleNode("NewDataSet");
                    //    initurl = MyXmlDoc.SelectSingleNode("NewDataSet").SelectSingleNode("Table").SelectSingleNode("Table").SelectSingleNode("FuncLinkAddr").InnerText;
                    int i = 0;
                    int TreeCount = MyXmlDoc.DocumentElement.ChildNodes.Count;
                    foreach (XmlNode MyNode in MyXmlDoc.DocumentElement.ChildNodes)
                    {
                      //  FirstNode[i] = MyNode.SelectSingleNode("NodeMenuPictureAddr").InnerText;           //一级节点名称和code
                        FirstNode[i] = image[i];
                        FirstNodeCode[i] = MyNode.SelectSingleNode("DirNodeCode").InnerText;                        i = i + 2;                    }                    Menu1Count = TreeCount;
                    //循环添加一级节点 ,采用button 的方式,中间夹杂着table的表格。表格内隐藏着树桩目录。
                    //建立表格
                    for (i = 0; i < 2 * TreeCount; i++) //中间夹杂着table的表格
                    {
                        TableRow RowTemp = new TableRow();
                        TableCell CellTemp = new TableCell();                        RowTemp.Cells.Add(CellTemp);
                        RowTemp.Width = 10;
                        Menu.Rows.Add(RowTemp);
                    }                    //插入button;文本名称为一级目录名称
                    for (i = 0; i < 2 * TreeCount; i = i + 2)
                    {
                        ButtonTree[i] = new ImageButton();
                        ButtonTree[i].BackColor = System.Drawing.Color.WhiteSmoke;                        ButtonTree[i].BorderStyle = BorderStyle.None;
                        //  ButtonTree[i].BorderStyle = System.Web.UI.WebControls.BorderStyle.Ridge;
                        ButtonTree[i].Height = 30;
                        Menu.Rows[i].Height = 30;
                        Menu.Rows[i].Cells[0].Height = 30;
                        // Menu.Rows[i].BackColor = ButtonTree[i].BackColor;
                        Menu.Rows[i].BackColor = System.Drawing.Color.AliceBlue;
                        //  ButtonTree[i].Text = FirstNode[i];   //以及目录名字
                        ButtonTree[i].ImageUrl = FirstNode[i];
                        ButtonTree[i].ID = i.ToString();
                        ButtonTree[i].Width = Menu.Width;                        Menu.Rows[i].Cells[0].Controls.Add(ButtonTree[i]);                        Menu.Rows[i + 1].Height = 0;                        // ButtonTree[i].Click += new EventHandler(this.ButtonClick(ButtonTree[i],e));  
                        ButtonTree[i].Click += new ImageClickEventHandler(this.ButtonClick);                    }                    TreeHeight = 480 - 30 * TreeCount; //二级树的高度
                    if (!IsPostBack)
                    {
                        int DisFlag = MyFuncNodeAllowCfg.DisConnectDb();                    }
                }
            }
            else
            {
                Response.Write("<script>self.parent.location.href='login.aspx';</script>");
            }
        } 
         
}
晕了,字数有限,不能全放上来了,就放到提示:无法连接数据库这里吧,我也不太懂啥意思,呵,帮忙看看,所有的需要连接数据库的都是不能连接数据库,帮忙看看,急死我了,好像是我系统的问题,帮忙看看代码,看我是不是还需要配置些什么..谢谢了.

解决方案 »

  1.   

    web.config的内容<?xml version="1.0"?>
    <!-- 
        Note: As an alternative to hand editing this file you can use the 
        web admin tool to configure settings for your application. Use
        the Website->Asp.Net Configuration option in Visual Studio.
        A full list of settings and comments can be found in 
        machine.config.comments usually located in 
        \Windows\Microsoft.Net\Framework\v2.x\Config 
    -->
    <configuration>
    <appSettings/>
    <system.web>
    <customErrors mode="Off"/>
    <!-- 
                Set compilation debug="true" to insert debugging 
                symbols into the compiled page. Because this 
                affects performance, set this value to true only 
                during development.
            -->
    <compilation debug="true">
    <assemblies>
    <add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <add assembly="Microsoft.VisualC, Version=8.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/></assemblies></compilation>
    <!--
                The <authentication> section enables configuration 
                of the security authentication mode used by 
                ASP.NET to identify an incoming user. 
            -->
    <authentication mode="Windows"/>
    <!--
                The <customErrors> section enables configuration 
                of what to do if/when an unhandled error occurs 
                during the execution of a request. Specifically, 
                it enables developers to configure html error pages 
                to be displayed in place of a error stack trace.        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
                <error statusCode="403" redirect="NoAccess.htm" />
                <error statusCode="404" redirect="FileNotFound.htm" />
            </customErrors>
            -->
    <globalization requestEncoding="GB2312" responseEncoding="GB2312"/>
    </system.web>
    </configuration>