2

I changed my database from SQL Server 2005 to SQL Server 2008 and now I'm having this error message. The site was working perfectly before changing the database

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 

Thanks

EDIT

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);
    }
}

If I used using system I get the error below:

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 
John Saunders
  • 160,644
  • 26
  • 247
  • 397
ponzu
  • 35
  • 6
  • 6
    Search your `Default.aspx.cs`. In the first line you have this ` App_Web_clientusing System;` and as you can see this is not a valid statement in C# – Steve May 30 '13 at 08:25
  • show your code for `Default.aspx.cs` page – Sachin May 30 '13 at 08:25
  • In Line 1 of Default.aspx.cs page remove the word App_Web_client . it should be just using System; – Jomy John May 30 '13 at 08:28
  • 1
    @Sachin, I have edited my post and included the code for Default.aspx.cs. Thanks – ponzu May 30 '13 at 09:10

2 Answers2

2

Just change the following

App_Web_clientusing System;

to

using System;
Saravanan
  • 7,637
  • 5
  • 41
  • 72
  • I tried your suggestion but there's an error. Please see my edited post. Thanks – ponzu May 30 '13 at 09:11
  • IT states that you have a wrong password for connecting to the DB. Go to the configuration file and then to the `` section and then update the password for the `User Id=sa` and then post the update for us – Saravanan May 30 '13 at 10:01
  • 1
    I changed the password for 'sa' in the SQL Server Management Studio but the error is still the same. I checked the Server Roles and only 'public and sysadmin' are checked. I tried checking the others like 'serveradmin' but the system doesn't allow me to do that. It says 'Cannot use the special principal 'sa'. Thanks – ponzu May 30 '13 at 10:45
  • I have mentioned you to update the password in the connectionstring section in the application. Please do not update in the Sql Server. It will affect other users also. – Saravanan May 30 '13 at 11:10
  • 1
    It's local and no other users are connecting. Thanks – ponzu May 30 '13 at 11:14
  • Okay. did you update the password in the connectionstring section of the config file – Saravanan May 30 '13 at 11:18
  • Fixed. I just need to change settings of Server authentication from 'Windows Authentication mode' to SQL Server and Windows Authentication mode'. from this link http://msdn.microsoft.com/en-us/library/ms187109.aspx I found the error 'Server is configured for Windows authentication only' and found the solution in this link http://stackoverflow.com/questions/8441158/an-attempt-to-login-using-sql-authentication-failed. All in all there are two steps that fixex my problem. changing 'App_Web_clientusing System' to 'using System' and changing security for 'Server Authentication'. Thank you so much:) – ponzu May 30 '13 at 12:53
0

This is zero to do with a database engine migration - it's the code causing the application to appear broken as it can't compile. Look at the error message and surrounding information and there is more than enough information to diagnose and fix this. That is, correcting your usings: App_Web_clientusing System; is invalid.

Grant Thomas
  • 44,454
  • 10
  • 85
  • 129
  • But it was working before I changed the database. After that I only changed the connection string for the database connection and It's no longer working. Thanks – ponzu May 30 '13 at 09:19