首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > ASP >

为什么asp中打不开数据库,该怎么处理

2012-05-22 
为什么asp中打不开数据库C# codeusing Systemusing System.Configurationusing System.Datausing Syste

为什么asp中打不开数据库

C# code
using System;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Data.SqlClient;public partial class _Default : System.Web.UI.Page {    protected void Page_Load(object sender, EventArgs e)    {    }           protected void Button1_Click(object sender, EventArgs e)    {        SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=FilmTicket;Integrated Security=True");     con.Open();                  SqlCommand cmd = new SqlCommand("select * from login where  login_ID='" + this.TextBox1.Text + "'and  login_pw='" + this.TextBox2.Text + "'", con);        SqlDataReader sdr = cmd.ExecuteReader();        if (sdr.Read())        {            Session["login_ID"] = sdr["login_ID"].ToString();            Session["login_pw"] = sdr["login_pw"].ToString();            Response.Write("<script language='javascript'>alert('登录成功欢迎使用系统');location.href='Index.aspx'</script>");        }        else        {            Response.Write("<script language='javascript'>alert('用户名或密码错误请重新登录');location.href='login.aspx'</script>");        }







sqlserver message 里的=FilmTicket使用Windows验证可登录啊







提示错误
“无法打开登录所请求的数据库 "FilmTicket"。登录失败。
用户 '这是电脑\薄暮传说' 登录失败。

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

异常详细信息: System.Data.SqlClient.SqlException: 无法打开登录所请求的数据库 "FilmTicket"。登录失败。
用户 '这是电脑\薄暮传说' 登录失败。

源错误: 

只有在调试模式下进行编译时,生成此未处理异常的源代码才会显示出来。若要启用此功能,请执行以下步骤之一,然后请求 URL: 

1. 在产生错误的文件的顶部添加一条“Debug=true”指令。例如: 

  <%@ Page Language="C#" Debug="true" %>

或:

2. 将以下的节添加到应用程序的配置文件中:

<configuration>
  <system.web>
  <compilation debug="true"/>
  </system.web>
</configuration>

请注意,第二个步骤将使给定应用程序中的所有文件在调试模式下进行编译;第一个步骤仅使该特定文件在调试模式下进行编译。

重要事项: 以调试模式运行应用程序一定会产生内存/性能系统开销。在部署到生产方案之前,应确保应用程序调试已禁用。

堆栈跟踪: 


[SqlException (0x80131904): 无法打开登录所请求的数据库 "FilmTicket"。登录失败。
用户 '这是电脑\薄暮传说' 登录失败。]
  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
  login.Button1_Click(Object sender, EventArgs e) +45
  System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
  System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
  System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
  System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
  System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
  System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

版本信息: Microsoft .NET Framework 版本:2.0.50727.5448; ASP.NET 版本:2.0.50727.5456









[解决办法]
把数据库登录模式改成SQL登录模式,设置用户名密码!
[解决办法]
不是在webconfig里连接数据库?如果在里面连接好了,使用的时候,加个用户名和密码就好了,不麻烦啊!
[解决办法]
那个你用id来做验证,不合适。还有在webconfig中连接数据库比较好
[解决办法]
检查你的WEB.CONFIG设置问题。你上面的代码没有错误。是你的WB里面的问题。
[解决办法]
把数据库登录模式改成SQL登录模式,设置用户名密码!

热点排行