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

为什么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 redirectedUserInst