连接字符串: 
     <add name="SurveyConnectionString" connectionString="Data Source=ECSHIT029\SQL2008;Initial Catalog=Wsi_Survey;Persist Security Info=True;User ID=sa;Password=sqlsa" providerName="System.Data.SqlClient"/>代码:
 public static DataTable Query(string strCmd)
    {
        using (SqlConnection cn = new SqlConnection(connectionString))
        {
            DataSet ds = new DataSet();            try
            {
                SqlCommand cmd = new SqlCommand(strCmd, cn);
                cn.Open();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(ds);
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                throw ex;
            }
            finally
            {
                cn.Close();
            }            return ds.Tables[0];
        }
    }调用代码:
        string _strCmd = "select q_eng from tbl_question where q_no = 1";        q_eng.Text = Db.Query(_strCmd).ToString();报错如下:
Server Error in '/WSI_Survey' Application.
--------------------------------------------------------------------------------Login failed for user 'sa'. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'sa'.Source Error: The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:1. Add a "Debug=true" directive at the top of the file that generated the error. Example:  <%@ Page Language="C#" Debug="true" %>or:2) Add the following section to the configuration file of your application:<configuration>
   <system.web>
       <compilation debug="true"/>
   </system.web>
</configuration>Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.  Stack Trace: 
[SqlException (0x80131904): Login failed for user 'sa'.]
   Db.Query(String strCmd) +157
   _Default.Page_Load(Object sender, EventArgs e) +23
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627 

解决方案 »

  1.   


    //Login failed for user 'sa'. sa登录失败
      

  2.   

    <add name="SurveyConnectionString" connectionString="Data Source=ECSHIT029\SQL2008;Initial Catalog=Wsi_Survey;Persist Security Info=True;User ID=sa;Password=sqlsa" providerName="System.Data.SqlClient"/>
    请确保你的User ID=sa;Password=sqlsa是正确账号密码
      

  3.   

    Login failed for user 'sa'.
    查看配置文件中 Uid and Pwd是否正确
      

  4.   


    如果是Vista或者Window7 VS右键管理员权限运行,再有看下SQL Sever服务器身份验证是不是SQL Server 和 Windows 身份验证模式。
      

  5.   

    分2点检查
    1,OS 是什么如果是 vista 需要确定执行该程序的权限
    2,检查PWD 是否正确。