SqlConnection conn=new SqlConnection("Server=myserver;Database=mydb;Uid=sa;pwd=");
conn.Open();这样写报错吗?

解决方案 »

  1.   

    键入conn.时,后面有方法弹出吗
      

  2.   

    试一下把Server=myserver改为 data source=myserver
      

  3.   

    谢谢!
    都试过了,还报同样的错!
    连接字符串从csdn中拷的,还报错!是否是系统有问题,还是visual studio.net未装好
    非常着急,请高手援手!!
      

  4.   

    用这样的连接串,再将数据库的相关权限赋给aspnet帐号,应该不会有问题
    string connstr="server=local);database=yourDB;Trusted_Connection=yes";
      

  5.   

    用这样的连接串,再将数据库的相关权限赋给aspnet帐号,应该不会有问题
    string connstr="server=local);database=yourDB;Trusted_Connection=yes";
      

  6.   

    全部代码如下:
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    namespace test
    {
    /// <summary>
    /// b 的摘要说明。
    /// </summary>
    public class b : System.Web.UI.Page 
    {
    public TextBox TextBox1;
    public Button Button1;
            public SqlConnection conn;
      public SqlDataAdapter cmd;
    public DataSet ds;
    public System.Web.UI.WebControls.DataGrid DataGrid1; 
    public b()
    {
    //
    // TODO: 在此处添加构造函数逻辑
    //

    }
            
    public void Button1_Click(object sender, System.EventArgs e)
    {
    string connstr="server=(local);database=db;Trusted_Connection=yes;Uid=sa;pwd="; 
    conn=new SqlConnection(connstr);
    conn.Open();

                           TextBox1.Text="ook!";
         }



    }
    }
    }
      

  7.   

    报错信息:
    Server Error in '/test' Application.
    --------------------------------------------------------------------------------Method not found: Void System.Threading.WaitCallback..ctor(System.Object, IntPtr). 
    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.MissingMethodException: Method not found: Void System.Threading.WaitCallback..ctor(System.Object, IntPtr).Source Error: 
    Line 33:  string connstr="server=(local);database=sx_customs;Trusted_Connection=yes;Uid=sa;pwd="; 
    Line 34:  conn=new SqlConnection(connstr);
    Line 35:  conn.Open();
    Line 36:  //SqlCommand cd =new SqlCommand("select * from id",conn);
    Line 37:  //cd.Connection=this.conn;
     Source File: e:\web\weba\test\b.cs    Line: 35 Stack Trace: 
    [MissingMethodException: Method not found: Void System.Threading.WaitCallback..ctor(System.Object, IntPtr).]
       System.Data.SqlClient.SqlConnection.Open() +761
       test.b.Button1_Click(Object sender, EventArgs e) in e:\web\weba\test\b.cs:35
       System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
       System.Web.UI.Page.ProcessRequestMain() +660 
    --------------------------------------------------------------------------------
    Version Information: Runtime Build:1.0.2914.16; ASP.NET Build:1.4000.2914.16
      

  8.   

    string connstr="server=(local);database=db;Trusted_Connection=yes;Uid=sa;pwd="; 
    ====这样连接的话,是不需要指定uid和pwd的啊,加上了反而有问题
      

  9.   

    string connstr="Initial Catalog=db;Data Source=localhost;Integrated Security=SSPI;";试试吧