你先确定数据库的登陆试试是不是允许使用sql server用户登陆的
把data source改为localhost试试

解决方案 »

  1.   

    是你连接字符串有问题,你用向导生成一个,连接到数据库,然后把Connection的connectionString帖出来看看。
      

  2.   

    我本来想用With windows NT authentication using the network login ID。
    我已经用过向导生成的connectionString,也不行啊
      

  3.   

    向导的可以,
    那代码的也一定可以的!
    你看看代码生成的时候,
    是不是提示你要不要把用户名和密码什么的一起显示出来?
    还是其它什么的/?
    认真比较一下,
    一定是ConnectionString的问题。
      

  4.   

    看看这个
    http://www.connectionstrings.com/
      

  5.   

    第一:你提供的代码中,其connection String没有定义Username 和password
    第二:问题可能就出在数据库上了。你先确保连接字符串的正确
    SqlConnection myConnection = new SqlConnection("data source=ZXW;initial catalog=TestId;username = yourloginame;password = yourloginpassword;workstation id=ZXW;packet size=4096");自动生成的ConnectionString如果单独复制过来也是不含密码的,但是有用户名,你这里用户名密码都没有。
      

  6.   

    你把connstring换掉:server=CAUC-XJ;database=ThePhile;uid=sa;pwd=sa;
      

  7.   

    我去看看http://www.connectionstrings.com/这个。选择这个With windows NT authentication using the network login ID不用用户名和密码,不过添上用户名和密码我也试过,不行。你把connstring换掉:server=CAUC-XJ;database=ThePhile;uid=sa;pwd=sa;----今晚换上边这个试一下
      

  8.   

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <appSettings>
        <!--   此处显示用户应用程序和配置的属性设置。-->
        <!--   示例:<add key="settingName" value="settingValue"/> -->
        <add key="sqlCommand1.CommandText" value=""/>
        <add key="ConnStr" value="user id=用户名;password=密码;initial catalog=数据库名;server=服务器名"/>
      </appSettings>        
     ......
    </configuration>web.config 中找上面的写,页面里边这样用:
    string ConnStr = ConfigurationSettings.AppSettings["ConnStr"];
            Conn = new SqlConnection(ConnStr);
    Conn.Open();
    别忘了:using System.Configuration;
      

  9.   

    在连接字符串中添加驱动提供者Provider=
      

  10.   

    mengfanpp(梦凡) and eTopFancy(你的美丽我的回忆)
    我昨晚试了,1。 Provider=SQLOLEDB.1 //VS.net自动生成
    2。 Provider= MicroSoft DataBase Driver for SQL Sever //要是我没记错,不过程序里肯定是写对了,在SQL Sever里抄的结果不行,说是Provider不对,怎么写,给个具体答案行不???
    谢谢
      

  11.   

    你把这一部分考到你的web.config 里面,把 用户名,密码,数据库名,服务器名改成你的用户名,密码,数据库名,服务器名,他们都没有引号的
      <appSettings>
        <!--   此处显示用户应用程序和配置的属性设置。-->
        <!--   示例:<add key="settingName" value="settingValue"/> -->
        <add key="sqlCommand1.CommandText" value=""/>
        <add key="ConnStr" value="user id=用户名;password=密码;initial catalog=数据库名;server=服务器名"/>
      </appSettings>  
    在*.aspx.cs页面中照下边用:string ConnStr = ConfigurationSettings.AppSettings["ConnStr"];
            Conn = new SqlConnection(ConnStr);
    Conn.Open();
    其他,任何东西都不用设置,不会出问题的,你再试试
      

  12.   

    mengfanpp(梦凡)
    我试过了,还是不行,我把Web.config, WEBFORM1.ASPX.CS 和 THE WRONG RESULT 都贴下边了,望给分析一下,看到地是那儿错了,我的程序了就一个WEBFORM1.ASPX.CS 页面是我加的,其他的都是默认生成的。Web.config<?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <appSettings>
        <!--   此处显示用户应用程序和配置的属性设置。-->
        <!--   示例:<add key="settingName" value="settingValue"/> -->
        <add key="sqlCommand1.CommandText" value=""/>
        <add key="ConnStr" value="user id=ZXW;password=123;initial catalog=TestDb;server=ZXW"/>
      </appSettings>  
    <system.web> <!--  DYNAMIC DEBUG COMPILATION
              Set compilation debug="true" to enable ASPX debugging.  Otherwise, setting this value to
              false will improve runtime performance of this application. 
              Set compilation debug="true" to insert debugging symbols (.pdb information)
              into the compiled page. Because this creates a larger file that executes
      ...... 
      ......
    <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
    </system.web>
    </configuration>
    WEBFORM.ASPX.CS
    using System;
    using System.Configuration;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;namespace MyTest1
    {
    /// <summary>
    /// Summary description for WebForm1.
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.DataGrid DataGrid1;

    private void Page_Load(object sender, System.EventArgs e)
    {
    // Put user code to initialize the page here
    if(!Page.IsPostBack)
    {
    string ConnStr = ConfigurationSettings.AppSettings["ConnStr"];
    SqlConnection Conn = new SqlConnection(ConnStr);
    Conn.Open();

    //Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=TestDb;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=ZXW;Use Encryption for Data=False;Tag with column collation when possible=False
    // SqlConnection myConnection = new SqlConnection("data source=localhost;initial catalog=TestId;workstation id=ZXW;packet size=4096");

    SqlDataAdapter myCommand = new SqlDataAdapter("use testdb SELECT * FROM Test",Conn); DataSet ds1 = new DataSet();
    myCommand.Fill(ds1, "Test1"); DataGrid1.DataSource=ds1.Tables["Test1"].DefaultView;
    DataGrid1.DataBind();
    Conn.Close();
    } } #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: This call is required by the ASP.NET Web Form Designer.
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {    
    this.DataGrid1.SelectedIndexChanged += new System.EventHandler(this.DataGrid1_SelectedIndexChanged);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
    {

    }
    }
    }THE WRONG RESULT:Server Error in '/MyTest1' Application.
    --------------------------------------------------------------------------------Login failed for user 'ZXW'. 
    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 'ZXW'.Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  Stack Trace: 
    [SqlException: Login failed for user 'ZXW'.]
       System.Data.SqlClient.SqlConnection.Open() +761
       MyTest1.WebForm1.Page_Load(Object sender, EventArgs e) +86
       System.Web.UI.Control.OnLoad(EventArgs e) +67
       System.Web.UI.Control.LoadRecursive() +29
       System.Web.UI.Page.ProcessRequestMain() +724
    --------------------------------------------------------------------------------
    Version Information: Microsoft .NET Framework Version:1.0.3705.0; ASP.NET Version:1.0.3705.0
      

  13.   

    我终于把它给连上了,用的是user id=sa; ……,而且数据库的Authentication必须选SQL Sever and Windows.我不明白Authentication为什么不能选Windows only?
      

  14.   

    还有:
    How should SQL Server verify the authenticity of the login ID?刚建数据库时有上面的问题,有下面两个选项:
    With windows NT authentication using the network login ID
    With SQL Sever authentication using a login ID and password entered by user.我连上的时候再没有改他,现在也忘了选哪个了,他们好像没什么用,有谁能告诉我他们到底在什么时候(或什么情况下)起什么作用?
      

  15.   

    用户名和密码要加上才行的要用SQL server验证,不要用WINNT验证