日期:2014-05-17  浏览次数:20411 次

VS2010连接数据库问题
最近在做ASP.NET实训。常识在ADO.NET连接数据库,但是连不上,代码如下:
 protected void Button1_Click(object sender, EventArgs e)
  {
  SqlConnection lin = new SqlConnection();
  lin.ConnectionString = "Data Source=SLEEPYBEAR-PC;Integrated Security=SSPI;Initial Catalog=Library";
  lin.Open();//报错语句
  Label1.Text="连接成功";
  lin.Close();
  lin.Dispose();
  }
数据库命,服务器命都没错,但是连接时就出现:
“/WebSite1”应用程序中的服务器错误。
--------------------------------------------

用户 'SleepyBear-PC\SleepyBear' 登录失败。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 

异常详细信息: System.Data.SqlClient.SqlException: 用户 'SleepyBear-PC\SleepyBear' 登录失败。

源错误: 


行 17: SqlConnection lin = new SqlConnection();
行 18: lin.ConnectionString = "Data Source=SLEEPYBEAR-PC;Integrated Security=SSPI;Initial Catalog=Library";
行 19: lin.Open();
行 20: Label1.Text="连接成功";
行 21: lin.Close();
 

源文件: d:\VS Project\WebSites\WebSite1\Default.aspx.cs 行: 19 

堆栈跟踪: 


[SqlException (0x80131904): 用户 'SleepyBear-PC\SleepyBear' 登录失败。]
  System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4856551
  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
  _Defa