string connectionString = "data source=.\\SQLEXPRESS; initial catalog=TestDatabse;persist security info=False;user id=Jordan-PC\\LiChen;password=123456;packet size=4096";myConnection = new System.Data.SqlClient.SqlConnection(connectionString);
            
myConnection.Open();
连接数据库的时候失败了,用sql server2008 新建的数据库“TestDatabse”,host是.\SQLEXPRESS,数据库是建立在Databases下面的,sql server2008的登陆Servername是.\SQLEXPRESS, authentication是windows authentication, username 是 Jordan-PC\LiChen, 没有要求输入密码,上面的connectionString里的123456是登陆本机登陆密码不知道哪里错了,在执行到open的时候就报错,返回的异常就是Login failed for user“Jordan-PC\LiChen”语句里都加了“\”符号来标明,调试也没有问题,求大牛指导,用本机账号登陆连接数据库不行么?

解决方案 »

  1.   

    你拖一个 数据源控件  配置一下不就有了吗?这个网站 有介绍  自己看一下吧
    http://www.connectionstrings.com/sql-server-2008
      

  2.   

    [SqlException (0x80131904): Login failed for user 'Jordan-PC\LiChen'.]
       System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4856727
       System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
       System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1121
       System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +35
       System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +144
       System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +340
       System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +225
       System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +189
       System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +185
       System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +31
       System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +431
       System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
       System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +499
       System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +65
       System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117
       System.Data.SqlClient.SqlConnection.Open() +122
       WebApplicationHelloWorld._Default.Page_Load(Object sender, EventArgs e) in C:\Users\LiChen\Documents\Visual Studio 2008\Projects\WebApplicationHelloWorld\WebApplicationHelloWorld\HelloWeb.aspx.cs:34
       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具体网页错误
      

  3.   

    Integrated Security=SSPI加了这个就可以了,神奇