日期:2014-05-18  浏览次数:20578 次

sql连接错误
程序如下:
<%@   Import   Namespace   =   "System.Data.SqlClient "%>
<%@   Import   Namespace   =   "System.Data "%>
<script   language   =   "C# "   runat   =   "server ">
protected   void   Page_Load(Object   sender,EventArgs   e)
{

string   strConn   =   "   server   =   (LENOVO-06164154);database   =   pubs;   uid   =sa;   pwd   =admin   ";
SqlConnection   Conn   =   new   SqlConnection(strConn);
string   sql   =   "select   *   from   Authors ";
SqlDataAdapter   Comm   =   new   SqlDataAdapter(sql,Conn);
DataSet   ds   =   new   DataSet();
Comm.Fill(ds, "Authors ");
MyDataGrid.DataSource   =   ds.Tables[ "Authors "].DefaultView;
MyDataGrid.DataBind();
}
</script>  

<asp:DataGrid   ID= "MyDataGrid "   Runat   =   "server "   />
错误信息如下:

源错误:  


行   10:   SqlDataAdapter   Comm   =   new   SqlDataAdapter(sql,Conn);
行   11:   DataSet   ds   =   new   DataSet();
行   12:   Comm.Fill(ds, "Authors ");
行   13:   MyDataGrid.DataSource   =   ds.Tables[ "Authors "].DefaultView;
行   14:   MyDataGrid.DataBind();
 

源文件:   D:\web\dababase\6-02.aspx         行:   12  

堆栈跟踪:  


[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.Data.Common.DbDataAdapter.QuietOpen(IDbConnection   connection,   ConnectionState&   originalState)
      System.Data.Common.DbDataAdapter.FillFromCommand(Object   data,   Int32   startRecord,   Int32   maxRecords,   String   srcTable,   IDbCommand   command,   CommandBehavior   behavior)
      System.Data.Common.DbDataAdapter.Fill(DataSet   dataSet,   Int32   startRecord,   Int32   maxRecords,   String   srcTable,   IDbCommand   command,   CommandBehavior   behavior)
      System.Data.Common.DbDataAdapter.Fill(DataSet   dataSet,   String   srcTable)
      ASP._6_02_aspx.Page_Load(Object   sender,   EventArgs   e)   in   D:\web\dababase\6-02.aspx:12
      System.Web.UI.Control.OnLoad(EventArgs   e)
      System.Web.UI.Control.LoadRecursive()
      System.Web.UI.Page.ProcessRequestMain()

 


------解决方案--------------------
string strConn = " server = (LENOVO-06164154);database = pubs; uid =sa; pwd =admin ";
=======================================================