日期:2014-05-18  浏览次数:20443 次

奇怪,同一段代码为何在winform中正常,在web中确会报错呢?
代码如下
winform中:
SqlConnectionStringBuilder   sb   =   new   SqlConnectionStringBuilder();
                        sb.DataSource   =   @ "My-PC\SQLEXPRESS ";
                        sb.InitialCatalog   =   "SuppierCount ";
                        sb.IntegratedSecurity   =   true;
                        SqlConnection   con   =   new   SqlConnection(sb.ToString());
                        SqlCommand   cmd   =   con.CreateCommand();
                        cmd.CommandText   =   "select   *   from   cpNote   order   by   NoteID ";
                        SqlDataAdapter   da   =   new   SqlDataAdapter((SqlCommand)cmd);
                        DataSet   ds   =   new   DataSet();
                        da.Fill(ds);

dataGridView1.DataSource   =   ds.Tables[0].DefaultView;

web中:
SqlConnectionStringBuilder   sb   =   new   SqlConnectionStringBuilder();
                        sb.DataSource   =   @ "My-PC\SQLEXPRESS ";
                        sb.InitialCatalog   =   "SuppierCount ";
                        sb.IntegratedSecurity   =   true;
                        SqlConnection   con   =   new   SqlConnection(sb.ToString());
                        SqlCommand   cmd   =   con.CreateCommand();
                        cmd.CommandText   =   "select   *   from   cpNote   order   by   NoteID ";
                        SqlDataAdapter   da   =   new   SqlDataAdapter((SqlCommand)cmd);
                        DataSet   ds   =   new   DataSet();
                        da.Fill(ds);

GridView1.DataSource   =   ds.Tables[0];
GridView1.DataBind();

在WinForm中,没有任何问题,正常显示表记录。
在Web中跟踪了一下运行到
da.Fill(ds);报错
错误:无法打开登录所请求的数据库   "SuppierCount "。登录失败。
用户   'My-PC\SQLEXPRESS '登录失败。

另外说明一下,我用系统自带的数据库master替换SuppierCount,在web中就正常了。
SuppierCount数据库是从附加到sql2005中的,不是直接在数据库中建的,现在我基本上认定是这样的原因引起的,可是为什么会这样的呢?Web中为什么不可以直接操作到附加的数据库呢?




------解决方案--------------------
去SuppierCount 把它设置成可以用window集成验证登陆
在这