【问题标题】:Changed database from SQL Server 2005 to SQL Server 2008将数据库从 SQL Server 2005 更改为 SQL Server 2008
【发布时间】:2013-05-30 08:23:36
【问题描述】:

我将数据库从 SQL Server 2005 更改为 SQL Server 2008,现在我收到此错误消息。该网站在更改数据库之前运行良好

Server Error in '/' Application.

Compilation Error

Description: An error occurred during the compilation of a resource required
             to service this request. Please review the following specific
             error details and modify your source code appropriately. 

Compiler Error Message: CS0116: A namespace cannot directly contain members
                                such as fields or methods

Source Error:    

Line 1:  App_Web_clientusing System;
Line 2:  using System.Collections;
Line 3:  using System.Configuration;

Source File: Default.aspx.cs    Line: 1 

谢谢

编辑

Default.aspx.cs

App_Web_clientusing System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SubSonic.Generated;
using SubSonic;
using HrcaPortal;


public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DisablePageCaching();
    }

    protected override void OnPreRender(EventArgs e)
    {
        int pageId = 0;
        int.TryParse(Request.QueryString["pageId"], out pageId);
        if (pageId > 0)
        {
            DataSet ds = HRCAWS.Admin.Misc.GetCommonPageContent(5);
            if (ds.Tables.Count > 0)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    DataTable dt = ds.Tables[0];
                    if (!dt.Rows[0].IsNull(0))
                    {
                        if (Convert.ToInt32(dt.Rows[0]["specialpageid"]) == pageId)
                            Response.Redirect("SendInquiryForPdSubs.aspx", true);
                    }
                }
            }
            PortalContentPage page = new PortalContentPage(pageId);
            //DataSet ds = PortalContentController.GetPortalMenuDS();
            //if (ds.Tables.Count > 0)
            //{
            //    if (ds.Tables[0].Rows.Count > 0)
            //    {
            //        DataTable dt = ds.Tables[0];
            //        DataRow[] dra = dt.Select("pageId = " + pageId);
            //        if (dra.Length > 0)
            //        {
                        ContentPane.InnerHtml = "<h1 id='title'>" + page.Title + "</h1>";
                        //use unescape as a decoding facility if you have used javascript string escape function to encode the html
                        ContentPane.InnerHtml += Microsoft.JScript.GlobalObject.unescape(page.Content);
            //        }
            //    }
            //}
        }
        else
        {
            DataSet ds = HRCAWS.Admin.Misc.GetCommonPageContent(4);
            if (ds.Tables.Count > 0)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    DataTable dt = ds.Tables[0];
                    ContentPane.InnerHtml = "<h1 id='title'>" + dt.Rows[0]["title"].ToString() + "</h1>";
                    ContentPane.InnerHtml += Microsoft.JScript.GlobalObject.unescape(dt.Rows[0]["content"].ToString());
                }
            }
        }

        base.OnInit(e);
    }

    public static void DisablePageCaching()
    {
        //Used for disabling page caching
        HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
        HttpContext.Current.Response.Cache.SetValidUntilExpires(false);
        HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
        HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        HttpContext.Current.Response.Cache.SetNoStore();
        HttpContext.Current.Response.Cache.SetNoServerCaching();
        HttpContext.Current.Response.Cache.SetSlidingExpiration(false);
        HttpContext.Current.Response.Cache.SetAllowResponseInBrowserHistory(false);
    }
}

如果我使用系统,我会收到以下错误:

Login failed for user 'sa'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'sa'.

Source Error: 


Line 44:            string parentIdCol, pageNameCol, pageIdCol, pageTypeCol, pageContentCol;
Line 45: 
Line 46:            DataSet ds = Gen.SPs.GetAllPortalMenuItems(true).GetDataSet();
Line 47: 
Line 48:            ds.DataSetName = "MenuItems";

Source File: App_Code\PortalContentController.cs    Line: 46 

【问题讨论】:

  • 搜索您的Default.aspx.cs。在第一行你有这个`App_Web_clientusing System;`,你可以看到这不是 C# 中的有效语句
  • 显示Default.aspx.cs页面的代码
  • 在 Default.aspx.cs 页面的第 1 行中删除单词 App_Web_client 。它应该只是使用 System;
  • @Sachin,我已经编辑了我的帖子并包含了 Default.aspx.cs 的代码。谢谢

标签: c# database sql-server-2008 sql-server-2005


【解决方案1】:

只需更改以下内容

App_Web_client 使用系统;

using System;

【讨论】:

  • 我尝试了您的建议,但出现错误。请看我编辑的帖子。谢谢
  • IT 声明您连接数据库的密码错误。转到配置文件,然后转到&lt;connectionStrings&gt; 部分,然后更新User Id=sa 的密码,然后为我们发布更新
  • 我在 SQL Server Management Studio 中更改了“sa”的密码,但错误仍然相同。我检查了服务器角色,只检查了“公共和系统管理员”。我尝试检查其他人,例如“serveradmin”,但系统不允许我这样做。它说'不能使用特殊主体'sa'。谢谢
  • 我已经提到您在应用程序的连接字符串部分更新密码。请不要在 Sql Server 中更新。它也会影响其他用户。
  • 它是本地的,没有其他用户正在连接。谢谢
【解决方案2】:

这与数据库引擎迁移无关 - 这是导致应用程序出现故障的代码,因为它无法编译。查看错误消息和周围信息,有足够的信息来诊断和解决这个问题。也就是说,更正你的用法:App_Web_clientusing System; 是无效的。

【讨论】:

  • 但在我更改数据库之前它正在工作。之后我只更改了数据库连接的连接字符串,它不再工作。谢谢
猜你喜欢
  • 1970-01-01
  • 2023-04-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多