当前位置:编程学习 > C#/ASP.NET >>

c# .NTE数据库连接不上,高手帮忙看看代码哪里出了问题。

public partial class _Default : System.Web.UI.Page
{
    BLL.AboutUs ba = new BLL.AboutUs();
    BLL.News bn = new BLL.News();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            show();
            Session["wew"] = null;
            Session["tianlong"] = "true";
        }
    }

    public void show()
    {
        DAL.About_us da = new DAL.About_us();
        da = ba.SelectAboutUs();
        labAddress.Text = da.Address;
        labTel.Text = da.Tel;
        labFax.Text = da.Fax;
        labweiboT.Text = da.WeiboT;
        labweiboW.Text = da.WeiboW;
        AweiboW.HRef = da.WeiboWAddress;
        AweiboT.HRef = da.WeiboTAddress;
        aMSN.HRef = "http://snind.gotdns.com:8080/message/msn/"; + da.MSN;
        aQQ.HRef = "http://wpa.qq.com/msgrd?v=1&;uin=" + da.QQ;


        //FlashImg
        repFlashImg.DataSource = bn.selectFlashImgListSlong();
        repFlashImg.DataBind();
        //新闻
        repNews.DataSource = bn.SelectAboutUsList5(2);
        repNews.DataBind();
        //汽车图片
        repCarpictures.DataSource = bn.selectCarPictureSList(2, 10);
        repCarpictures.DataBind();
    }

    public string todate(string date)
    {
        string dd = Convert.ToDateTime(date).ToShortDateString();
        return dd;
    }

    public string substring(string str, int lenth)
    {
        string restr = str;
        if (str.Length > lenth)
        {
            restr = str.Substring(0, lenth) + "...";
        }

        return restr;
    }

}

检查过web.config文件配置应该没问题。 --------------------编程问答-------------------- 有没有相关异常信息,lz 贴出来看下 --------------------编程问答-------------------- 看局部代码是声明ba,bn地方,你看看是不是声明后需要再执行一下,例如,bn.open什么的,具体是什么 看看这部分的源代码。
--------------------编程问答-------------------- 应该是数据库连接错误,是远程连接数据库,看是否支持远程连接。 --------------------编程问答--------------------
引用 楼主 luojiankeji 的回复:
public partial class _Default : System.Web.UI.Page
{
    BLL.AboutUs ba = new BLL.AboutUs();
    BLL.News bn = new BLL.News();

    protected void Page_Load(object sender, EventArgs ……

把你的代码不断地删除,留下的代码要求必须能够连上数据库。直到删得只剩下与“连接数据库”唯一相关的代码,再来问问题。

当你贴出一大堆无关的代码塞给别人“请帮我看看”,别人就懒得跟你说了。 --------------------编程问答-------------------- 问一句 连接代码 在那里 --------------------编程问答-------------------- 这是一朋友叫帮忙给看下的,我看了半天,貌似就是链接代码的问题,我也没找到读取数据库的代码在哪里 --------------------编程问答-------------------- 这个代码怎么读取的数据库我不知道
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,