| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 589 人关注过本帖
标题:求助:SQL Server 不存在或访问被拒绝。
只看楼主 加入收藏
ershiyi
Rank: 1
等 级:新手上路
帖 子:56
专家分:0
注 册:2006-3-15
收藏
 问题点数:0 回复次数:0 
求助:SQL Server 不存在或访问被拒绝。
using System;
using System.Collections;
using
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration ;
using System.Data .SqlClient ;

namespace hcylb
{
    /// <summary>
    /// AdvancedSearch 的摘要说明。
    /// </summary>
    public class AdvancedSearch : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.HyperLink HyperLink1;
        protected System.Web.UI.WebControls.TextBox tbx_bid;
        protected System.Web.UI.WebControls.TextBox tbx_bname;
        protected System.Web.UI.WebControls.TextBox tbx_bauthor;
        protected System.Web.UI.WebControls.TextBox tbx_bisbn;
        protected System.Web.UI.WebControls.TextBox tbx_bpress;
        protected System.Web.UI.WebControls.Button btn_search;
        protected System.Web.UI.WebControls.TextBox tbx_btheme;
        protected System.Web.UI.WebControls.DataGrid dgd_booklist;
    
        private void Page_Load(object sender, System.EventArgs e)
        {
            if(!IsPostBack) BindGrid();
        }

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN:该调用是 Web 窗体设计器所必需的。
            //
            InitializeComponent();
            base.OnInit(e);
        }
        
        /// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {   
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion


        public void DataGrid_Page(Object sender,DataGridPageChangedEventArgs E)
        {
            dgd_booklist.CurrentPageIndex =E.NewPageIndex ;
            BindGrid();
        }
        public void BindGrid()
        {    //从文件Web.config中读取连接字符串
            string strconn= ConfigurationSettings.AppSettings["dsn"];
            //连接本地计算机的LMS数据库
            SqlConnection cn= new SqlConnection (strconn);
            //创建带筛子的SQL语句
            string mysql="select * from book where 1=1";
            //对控建进行筛选
            if (tbx_bid.Text .ToString ()!="")//如果“书号”有输入
            {
                try
                {
                    mysql=mysql+" and bid="+Convert.ToInt32 (tbx_bid.Text .ToString ());
                }
                catch
                {    
                    Response.Write ("书号输入有误!");
                    Response.End();
                }
            }
            if (tbx_bname.Text .ToString ()!="")//如果“书名”有输入
            {
                mysql=mysql+" and bname like '%"+tbx_bname.Text .ToString ()+"%'";
            }
            if (tbx_bauthor.Text .ToString ()!="")//如果“书作者”有输入
            {
                mysql=mysql+" and bauthor like '%"+tbx_bauthor.Text .ToString ()+"%'";
            }
            if (tbx_bisbn.Text .ToString ()!="")//如果“书ISBN”有输入
            {
                mysql=mysql+" and bisbn='"+tbx_bisbn.Text .ToString ()+"'";
            }
            if (tbx_bpress.Text .ToString ()!="")//如果“书出版社”有输入
            {
                mysql=mysql+" and bpress like '%"+tbx_bpress.Text .ToString ()+"%'";
            }
            if (tbx_btheme.Text .ToString ()!="")//如果“主题词”有输入
            {
                mysql=mysql+" and btheme like '%"+tbx_btheme.Text .ToString ()+"%'";
            }
            //创建SqlDataAdapter对象,调用视图
            SqlDataAdapter da=new SqlDataAdapter (mysql,cn);
            //创建并填充DataSet
            DataSet ds=new DataSet ();
            da.Fill (ds);
            dgd_booklist.DataSource =ds;
            dgd_booklist.DataBind ();
            cn.Close ();
        }

        private void btn_search_Click(object sender, System.EventArgs e)
        {
            BindGrid();
        }

        
    }
}
在调试时就出现:
SQL Server 不存在或访问被拒绝。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.Data.SqlClient.SqlException: SQL Server 不存在或访问被拒绝。
源错误:


行 105:            //创建并填充DataSet
行 106:            DataSet ds=new DataSet ();
行 107:            da.Fill (ds);
行 108:            dgd_booklist.DataSource =ds;
行 109:            dgd_booklist.DataBind ();
 

源文件: d:\hcylb\advancedsearch.aspx.cs    行: 107

堆栈跟踪:


[SqlException: SQL Server 不存在或访问被拒绝。]
   System.Data.SqlClient.ConnectionPool.GetConnection(Boolean& isInTransaction)
   System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction)
   System.Data.SqlClient.SqlConnection.Open()
   System.(IDbConnection connection, ConnectionState& originalState)
   System.(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   System.(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   System.(DataSet dataSet)
   LMS.AdvancedSearch.BindGrid() in d:\hcylb\advancedsearch.aspx.cs:107
   LMS.AdvancedSearch.Page_Load(Object sender, EventArgs e) in d:\hcylb\advancedsearch.aspx.cs:33
   System.Web.UI.Control.OnLoad(EventArgs e)
   System.Web.UI.Control.LoadRecursive()
   System.Web.UI.Page.ProcessRequestMain()
请问问题在哪里?该怎么改?
搜索更多相关主题的帖子: using System SQL Server Web 
2008-05-11 15:19
快速回复:求助:SQL Server 不存在或访问被拒绝。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021476 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved