这是源代码:using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;public partial class login1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {    }
    protected void submit_Click(object sender, EventArgs e)
    {
        string name = this.txtusn.Text.Trim();
        string pass = this.txtpsw.Text.Trim();        string realName = this.txtname.Text.Trim();
        string sex = "";
        if (RadioBtn1.Checked)
        {
            sex = "男";        }
        else sex = "女";
        string qq = this.txtQQ.Text.Trim();
        string tel = this.txttel.Text.Trim();
        string email = this.txte.Text.Trim();
                SqlConnection conn = new DBConn().getConnection();
      
        string mySQL = "insert into Users(u_Name,u_Pass,u_Realname,u_Sex,u_QQ,u_Tel,u_Email) values('";
        mySQL += name + "','" + pass + "','" + realName + "','" + sex + "','" + qq + "','" + tel + "','" + email + "')";        SqlDataAdapter sda = new SqlDataAdapter(mySQL, conn);
        DataSet ds = new DataSet();
      sda.Fill(ds);    }
}
这是错误提示提示在最后一句 sda.fill(ds)
用户代码未处理 System.Data.SqlClient.SqlException
  Message="在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接)"
  Source=".Net SqlClient Data Provider"
  ErrorCode=-2146232060
  Class=20
  LineNumber=0
  Number=2
  Server=""
  State=0
  StackTrace:
       在 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
       在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
       在 System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject)
       在 System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)
       在 System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
       在 System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
       在 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
       在 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
       在 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
       在 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
       在 System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
       在 System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
       在 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
       在 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
       在 System.Data.SqlClient.SqlConnection.Open()
       在 System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, 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)
       在 login1.submit_Click(Object sender, EventArgs e) 位置 e:\mylyb\login1.aspx.cs:行号 46
       在 System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       在 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
       在 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       在 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       在 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: 

解决方案 »

  1.   

    你是不是有的SQL服务没启动啊。。你这个数据库不允许连接。。
      

  2.   

    看一下你的数据库链接,如果是用IP的话,把IP改成"."来试一下
      

  3.   


    http://blog.csdn.net/zhangyang0402/archive/2007/05/07/1598646.aspx
      

  4.   

    using System;
    using System.Data;
    using System.Configuration;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.Data.SqlClient;/// <summary>
    ///DBConn 的摘要说明
    /// </summary>
    public class DBConn
    {
    public DBConn()
    {
    //
    //TODO: 在此处添加构造函数逻辑
    //
            
    }
        public SqlConnection getConnection()
        {
          
            return new SqlConnection("server=.;database=Messages;uid=sa;pwd=sa123456");
         }
    }