请教一个asp.net连接sql问题
无法打开登录所请求的数据库 "db_Sell"。登录失败。用户 'FE517C2A88FC42D\Administrator' 登录失败。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.SqlClient.SqlException: 无法打开登录所请求的数据库 "db_Sell"。登录失败。
用户 'FE517C2A88FC42D\Administrator' 登录失败。
源错误:
行 42: }
行 43: SqlConnection strcon = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["strcon"]);
行 44: strcon.Open();
行 45: SqlCommand scd = new SqlCommand("select count(*) as ff from tb_user where username='"+username+"' and userpwd='"+userpwd+"'",strcon);
行 46: int count = Convert.ToInt32(scd.ExecuteScalar());
源文件: c:\Documents and Settings\Administrator\桌面\超市信息管理系统\超市信息管理系统\程序\login.aspx.cs 行: 44
堆栈跟踪:
[SqlException (0x80131904): 无法打开登录所请求的数据库 "db_Sell"。登录失败。
用户 'FE517C2A88FC42D\Administrator' 登录失败。]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +117
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +346
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +3227
System.Data.SqlClient.(Boolean enlistOK) +56
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +1083
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +272
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +687
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +82
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +558
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +126
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +651
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +160
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +122
System.Data.SqlClient.SqlConnection.Open() +229
login.ImageButton1_Click(Object sender, ImageClickEventArgs e) in c:\Documents and Settings\Administrator\桌面\超市信息管理系统\超市信息管理系统\程序\login.aspx.cs:44
System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +102
System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +141
System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +72
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3838
我想用windows验证模式登入数据库,之后就出现上述问题了,不知道怎么改,请高手指点
<add key="strcon" value="server=.;database=db_Sell;Integrated Security=True;"></add>
还有
SqlConnection strcon = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["strcon"]);
strcon.Open();
SqlCommand scd = new SqlCommand("select count(*) as ff from tb_user where username='"+username+"' and userpwd='"+userpwd+"'",strcon);
还有一个问题:能否把数据库放在App_Code里,等程序启动后就可以连上数据库,而不用再添加数据库呢