Pages

Search This Blog

Friday, October 19, 2007

Server Error in '/'Application. Configuration Error

Error Message on web.config when setting up a new application.

Server Error in '/'Application.

Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: Unrecognized attribute 'requirePermission'.

Change the ASP.NET version to the correct version.



Problem solved.

Thursday, October 18, 2007

Must declare the scalar variable "@UserId".

We are doing server migration testing. I've restored a DB from production to staging server. I setup up a ASP.NET application and point to production server, everything work fine but when point to staging server, error below appear. By the way, we are using MS SQL 2005 standard edition in both server.

Server Error in '/' Application.

Must declare the scalar variable "@UserId".
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: Must declare the scalar variable "@UserId".

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[SqlException (0x80131904): Must declare the scalar variable "@UserId".]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +862234
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +739110
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1956
System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +31
System.Data.SqlClient.SqlDataReader.get_MetaData() +62
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +903
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +132
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +122
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior) +62
Dal.GetRecentRater(Int32 PostId, DataTable dt) +190
Post.BindBlogPost() +1295
Post.Page_Load(Object sender, EventArgs e) +49
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061










At this point, i suspect something wrong with the staging server DB. So i access to the staging server and execute the stored procedure in Query Panel and it give me some error message.
Must declare the scalar variable "@UserId".







I open and check the stored procedure and the stored procedure is simple

ALTER PROCEDURE [dbo].[GetUserDetails]
@UserId int
as
select * from Users where UserId = @UserID


After check for a while, i change the @UserID to @UserId and magic happened. Problem solved. It's case sensitive.

It's strange because this stored procedure running in production server without any problem. Collation for both MS SQL 2005 DB are SQL_Latin1_General_CP1_CI_AS.

Tuesday, October 16, 2007

DataList Paging

There are always a problem to customize paging for DataList as below.

I'm able to develop a DataList Paging for my own application. Credit should give to Netomatix.
Please download and check the sample source code from my testing.
For testing purpose, i use Northwind database and i've created a new stored proc called: GetProductByCategory










Stored Procedure: GetProductByCategory

CREATE PROCEDURE [dbo].[GetProductByCategory]
@PageIndex INT,
@NumRows INT,
@Discontinued BIT = 1
AS
BEGIN
SET NOCOUNT ON
DECLARE @StartRowIndex INT;
SET @StartRowIndex = (@PageIndex * @NumRows) + 1;
WITH myProducts AS(
SELECT ProductID, ProductName, UnitPrice,
CategoryName, Description, UnitsInStock,
ROW_NUMBER() OVER(ORDER BY ProductID DESC) as Row,
count(*) over() AS ResultRowCount, Discontinued
FROM Products P
INNER JOIN Categories C
ON P.CategoryID = C.CategoryID
WHERE Discontinued = @Discontinued
)
SELECT * FROM myProducts
WHERE Row BETWEEN @StartRowIndex AND (@StartRowIndex + @NumRows)-1
ORDER BY ProductID ASC
SET NOCOUNT OFF
END

Monday, October 15, 2007

Could not load type '_Default'

Server Error in '/DataListPage' Application.

Parser Error

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

Parser Error Message: Could not load type '_Default'.

Source Error:

Line 1: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" % >
Line 2:
Line 3: http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
">

I'm able to run my application in Visual Studio, when try to open the application directly from IE, i get this error. After check for a while, i found that it's the problem for the ASP.NET Version that selected. After i change to ASP.NET 2.0.50727, problem solved.

ASP.NET wrapper for Twitter API

I was developing a ASP.NET wrapper for Twitter API and end up using the wrapper provided by Yedda. Credit should to Yedda.

Download the wrapper from Yedda. Unzip the files and you can play around with the project.

What i do is
  1. Create a new class name TwitterWrapper in my App_Code
  2. Copy the code from Twitter.cs and paste in TwitterWrapper.cs

to twitter your message:

string xmlOutput = "";
string TwitterUserName = "username";
string TwitterPassword = "password";

string TwitterMessage = "Hello twitter";

if (TwitterUserName != "" && TwitterPassword != "")
{
try
{
TwitterWrapper twitter = new TwitterWrapper();
xmlOutput = twitter.Update(TwitterUserName, TwitterPassword, TwitterMessage, TwitterWrapper.OutputFormatType.XML);
}
catch (Exception ex)
{ }
finally
{ }
}

Sunday, October 14, 2007

System.Web.HttpParseException: Could not load the assembly App_Web_xxxx. Make sure that it is compiled before accessing the page.

I always received error message from the web application after the last deployment.

System.Web.HttpParseException: Could not load the assembly 'App_Web_fsfkjwna'. Make sure that it is compiled before accessing the page. ---> System.Web.HttpParseException: Could not load the assembly 'App_Web_fsfkjwna'. Make sure that it is compiled before accessing the page. ---> System.Web.HttpParseException: Could not load the assembly 'App_Web_fsfkjwna'. Make sure that it is compiled before accessing the page. ---> System.Web.HttpException: Could not load the assembly 'App_Web_fsfkjwna'. Make sure that it is compiled before accessing the page.at System.Web.UI.TemplateParser.GetType(String typeName, Boolean ignoreCase, Boolean throwOnError)at System.Web.UI.TemplateParser.ProcessInheritsAttribute(String baseTypeName, String codeFileBaseTypeName, String src, Assembly assembly)at System.Web.UI.TemplateParser.PostProcessMainDirectiveAttributes(IDictionary parseData)--- End of inner exception stack trace ---at System.Web.UI.TemplateParser.ProcessException(Exception ex)at System.Web.UI.TemplateParser.PostProcessMainDirectiveAttributes(IDictionary parseData)at System.Web.UI.PageParser.PostProcessMainDirectiveAttributes(IDictionary parseData)at System.Web.UI.TemplateParser.ProcessMainDirective(IDictionary mainDirective)at System.Web.UI.TemplateControlParser.ProcessMainDirective(IDictionary mainDirective)at System.Web.UI.PageParser.ProcessMainDirective(IDictionary mainDirective)at System.Web.UI.TemplateParser.ProcessDirective(String directiveName, IDictionary directive)at System.Web.UI.BaseTemplateParser.ProcessDirective(String directiveName, IDictionary directive)at System.Web.UI.TemplateControlParser.ProcessDirective(String directiveName, IDictionary directive)at System.Web.UI.PageParser.ProcessDirective(String directiveName, IDictionary directive)at System.Web.UI.TemplateParser.ParseStringInternal(String text, Encoding fileEncoding)--- End of inner exception stack trace ---at System.Web.UI.TemplateParser.ProcessException(Exception ex)at System.Web.UI.TemplateParser.ParseStringInternal(String text, Encoding fileEncoding)at System.Web.UI.TemplateParser.ParseString(String text, VirtualPath virtualPath, Encoding fileEncoding)--- End of inner exception stack trace ---at System.Web.UI.TemplateParser.ParseString(String text, VirtualPath virtualPath, Encoding fileEncoding)at System.Web.UI.TemplateParser.ParseFile(String physicalPath, VirtualPath virtualPath)at System.Web.UI.TemplateParser.ParseInternal()at System.Web.UI.TemplateParser.Parse()at System.Web.Compilation.BaseTemplateBuildProvider.get_CodeCompilerType()at System.Web.Compilation.BuildProvider.GetCompilerTypeFromBuildProvider(BuildProvider buildProvider)at System.Web.Compilation.BuildProvidersCompiler.ProcessBuildProviders()at System.Web.Compilation.BuildProvidersCompiler.PerformBuild()at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert)at System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert)at System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)at System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)at System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)




After struggling for a while, i found that by doing 2 steps can solve this problem.




  1. Create a new Application Pool.

  2. Change the application pool for my application to the newly created pool.


Create new Application Pool in Internet Information Server 6 (Windows Server 2003)




  1. Open IIS 6


  2. Right click on Application Pools node from the tree view


  3. Select New -> Application Pool ... from the context menu


  4. Enter Application pool ID (myAppPool) and click OK.


  5. New Application Pool Created.



  6. Change the application pool for my application to the newly created pool.

  7. Open IIS
  8. From the explorer view, open the Web Sites folder.


  9. Point to the web application that want to change the Application Pool (mysite.com)


  10. Right click on mysite.com


  11. Select Properties


  12. A new Properties window pop up, Select "Home Directory" tab


  13. Change the Application Pool to "myAppPool" and click OK.


  14. Application Pool Changed


  15. Done.

    For Windows XP developer, when face this error, Kill aspnet_wp.exe process,

    go to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files and delete all the temporary files. Try to compile your project again.


    Saturday, October 13, 2007

    remove "Yahoo Toolbar" from Firefox



    Open Mozilla Firefox,
    Go to Tools Menu, Click On Add-ons
    A new Add-ons windows popup, Select Yahoo Toolbar and click on Unistall button.
    Done

    ASP.NET Cookies

    Cookies is Domain dependent. Cookies created under subdomain beta.mydomain.com will not able to retrive when access to www.mydomain.com. To ensure that we can retrive the same cookies, we need to specify the domain
    For example, we want to write the information to cookies under mydomain when we access to url beta.mydomain.com

    HttpCookie cook = new HttpCookie("mydomain");
    Response.Cookies.Clear();
    Response.Cookies.Add(cook);
    cook["UserId"] = userId;
    cook["Name"] = username.Text;
    cook.Expires = DateTime.MaxValue;
    Response.Cookies.Add(cook);

    To retrive the cookies information:

    if (Request.Cookies["mydomain"] != null)
    {
    if (Request.Cookies["mydomain"]["UserId"] != null && Request.Cookies["mydomain"]["Name"] != null)
    {
    Session["UserId"] = Convert.ToInt32(Request.Cookies["mydomain"]["UserId"].ToString());
    Session["UserName"] = Request.Cookies["mydomain"]["Name"].ToString();
    }
    }

    Wednesday, October 10, 2007

    Cannot implicitly convert type 'string' to 'System.Net.Mail.MailAddress'

    I got error "Cannot implicitly convert type 'string' to 'System.Net.Mail.MailAddress' "

    MailMessage msg = new MailMessage();
    msg.From = "info@xxx.com";
    msg.To = "comments@xx.com";
    msg.Bcc = "keith@xxx.com";

    msg.Subject = "Comment";
    msg.Body = "Comment: xxxxxxx xxxxxxx xxxxxxx ";
    SmtpClient smtpClient = new SmtpClient();
    smtpClient.Host = Global.smtp;

    To solve the issue, i change to below code

    MailMessage msg = new MailMessage();
    msg.From = new System.Net.Mail.MailAddress("info@xxx.com");
    msg.To.Add("comments@xx.com");
    msg.Bcc.Add("keith@xxx.com");

    msg.Subject = "Comment"; msg.Body = "Comment: xxxxxxx xxxxxxx xxxxxxx ";

    SmtpClient smtpClient = new SmtpClient();
    smtpClient.Host = Global.smtp;

    Tuesday, October 9, 2007

    Could not load file or assembly 'Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of ..........

    When deploy a ASP.NET application to a new server, error message below shown:

    Could not load file or assembly 'Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

    invoice software

    Here is the scenario:
    My ASP.NET App use AJAX.NET and ASP.NET AJAX Control Toolkit
    My application server have NO AJAX.NET and ASP.NET AJAX Control Toolkit installed.





    To solve my problem with no AJAX.NET install in my application server:

    1. Copy AjaxControlToolkit.dll and AjaxControlToolkit.pdb version 1.0.61025.0 from my development machine to my ASP.NET App bin folder. (i install my AjaxControlToolkit in C:\Program Files\Microsoft ASP.NET\ASP.NET 2.0 AJAX Extensions\AjaxControlToolkit)

    2. Copy System.Web.Extensions.dll (C:\WINDOWS\assembly\GAC_MSIL\System.Web.Extensions) and System.Web.Extensions.Design.dll (C:\WINDOWS\assembly\GAC_MSIL\System.Web.Extensions.Design) from my development machine to my ASP.NET App bin folder.
    Run the application and it's works.




    Alternatively, we can solve the problem by installing AJAX.NET and AjaxControlToolkit to the server.