Showing posts with label Errors and Solution. Show all posts
Showing posts with label Errors and Solution. Show all posts

Monday, November 17, 2014

Could not locate the assembly "System.Web.Mvc,Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35,processorArchitecture=MSIL

Microsoft recent security update has resulted in compilation error.  After spending some time came across this link.  This is a known issue.

Error: Could not load file or assembly 'System.Web.Mvc, Version=4.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)


Cause of Error: Microsoft recent security update


Solution: Install Nuget Package Microsoft.AspNet.Mvc for all the project referencing System.Web.Mvc dll
Example: Install-Package Microsoft.AspNet.Mvc 

Sunday, November 16, 2014

Attempt by security transparent method 'WebMatrix.WebData.PreApplicationStartCode.Start()' to access security critical method 'System.Web.WebPages.Razor.WebPageRazorHost.AddGlobalImport(System.String)' failed.


Error: Attempt by security transparent method 'WebMatrix.WebData.PreApplicationStartCode.Start()' to access security critical method 'System.Web.WebPages.Razor.WebPageRazorHost.AddGlobalImport(System.String)' failed.


Solution: Install Nuget Package Microsoft.AspNet.WebHelpers
Example: Install-Package Microsoft.AspNet.WebHelpers


Could not load file or assembly 'WebMatrix.Data, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)


Error: Could not load file or assembly 'WebMatrix.Data, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Solution: Install Nuget Package Microsoft.AspNet.WebPages.Data
Example: Install-Package Microsoft.AspNet.WebPages.Data


Monday, September 08, 2014

Solution: SSD Drive not getting detected on Win 10 OS

Recently I have purchase Samsung - 850 EVO 500GB Internal Serial ATA Solid State Drive for Laptops - Black (Model: MZ-75E500B)  in order to boost the performance of my laptop.


Issue:  SSD Drive was not getting detected on Win 10 OS.

Solution:

This issue was occurring because SSD drive was new and their was no previous partition and disk was not been formatted.  Steps to overcome this problem:

  1. Open Control Panel
  2. Click on Administrative Tools
  3. Click on Computer Management
  4. Double click on Disk Management from the left pane.
  5. Select the unlabeled drive from middle pane. i.e. Select SSD Drive which will be unlabeled.
  6. Select disk from lower pane and right click > New Simple Volume...
  7. Click Next to the wizard for Size and drive letter.
  8. And then give drive a volume label name of your choice and begin format.
  9. Ones formatting is completed it will show: Healthy (Primary Partition).
  10. Now your disk drive will appear in windows explorer.


Refer to this video for more details and exact steps on how to perform: Why can I not see my new SSD or hard drive?



Issue:  Samsung Data Migration for cloning was not working on Win 10.

Error: Samsung Data Migration Cloning failed target disk has been disconnected -00001 (ffffffff)

Solution:

Samsung data migration utility CD which comes with SSD Drive hardware is still not compatible with Win 10, so you can either used different software for drive cloning or can degrade to previous version of windows on which samsung data migration utility will works just good.


Few other references you would find useful if run into any such issues:


Monday, December 10, 2012

Weird errors in asp.net mvc and its solution

If you are experiencing weird errors in asp.net mvc.

Situation 1
You have added namespace in Web.config file still your View Page is not reflecting any change or still control is error-ed out, then close the view and reopen it.  Yes VS.Net requires closing and opening of view page in order to reflect changes.


Situation 2
You have made major change in Entity Framework (Code First) Entity class and even though making sure that all changes are properly applied if you receive any runtime error saying "Invalid column name" or may be something as shown below:  Then simply close your asp.net mvc project (VS.Net Solution) and open it again. (Yes i found this weird because it requires me to close my vs.net solution and reopen it again to reflect all changes, even though i tried clean solution and rebuild solution before running project)


 at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
   at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
   at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
   at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable.GetEnumerator()
   at System.Data.Entity.Internal.Linq.InternalQuery`1.GetEnumerator()
   at System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable.GetEnumerator()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at MyBlog.Controllers.StepbystepController.Index() in d:\Websites\Source\MyBlog\MyBlog\Controllers\StepbystepController.cs:line 27
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass42.b__41()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.b__7(IAsyncResult _)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<>c__DisplayClass39.b__33()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.b__49()





Situation 3
You have change model in view then to apply changes you need to close view and reopen it again.


Now below situation are something becoz of our mistake but we don't generally noticed.  Mostly this errors result in 404 - Error Page.

If you are getting 404 Error in asp.net mvc then make sure
1) Check action name and then check view name.
Example: You have created "ContactMessage" action method in Home controller and you have created "Contact" view page, this mismatch will result in 404 error.  I know you new this but you don't realize this when 404 occurs.

2) Check whether you have created view page under correct directory name.  I will not go deep into Asp.net MVC Hierarchy structure but as you know that proper naming convention needs to follow, so by mistake if you have created view under wrong directory that will also results in 404 error page.

3) Check whether controls on your view is not error-ed out. (They are getting proper values assigned from model).

4) You can always turn CustomErrors mode="RemoteOnly" to simply attack problem at first.




There are few other situations but i can't able to recall them all, but you get the gist of my post.


Moral of story:  All errors mentioned here are either becoz of our mistake or vs.net, but we don't generally noticed, so if you run into similar situation then answer is relax and try to make sure that things are not becoz of your mistake before jumping into find solution.

Sunday, September 16, 2012

Error: Cannot insert explicit value for identity column in table 'Users' when IDENTITY_INSERT is set to OFF

I run into situation where i have to insert explicit value for identity column and run into following error, which is expected. Incase you run into similar situation here is the solution to insert value into Identity column in SQL Server.

Error: Msg 544, Level 16, State 1, Line 1
Cannot insert explicit value for identity column in table 'Users' when IDENTITY_INSERT is set to OFF.

Cause of error: Trying to insert record including ID field where ID field is IDENTITY Column.

Solution: 
1) Make sure that you are in situation where you really want to insert ID, If that is not the requirement than simply remove ID field from your insert statement and try to execute the insert statement again.

2) Since i was sure that i want to insert ID in Identity column, here is solution...

SET IDENTITY_INSERT YourTableName ON

INSERT INTO YourTableName
(IDENTITY Column, Column1...ColumnN)
VALUES
(IDENTITY Value, Value1, ...., ValueN)

SET IDENTITY_INSERT YourTableName OFF

Note:
Make sure that your insert statement does include all column name list, otherwise you will run into this error.

Error: 
Msg 8101, Level 16, State 1, Line 1
An explicit value for the identity column in table 'Users' can only be specified when a column list is used and IDENTITY_INSERT is ON.


Wrong Insert Statement
INSERT INTO YourTableName
VALUES
(IDENTITY Value, Value1, ...., ValueN)

Correct Insert Statement
INSERT INTO YourTableName
(IDENTITY Column, Column1...ColumnN)
VALUES
(IDENTITY Value, Value1, ...., ValueN)

Saturday, July 21, 2012

Error: Database could not be exclusively locked to perform the operation

You might receive "Database could not be exclusively locked to perform the operation" or many error like such when you are trying to perform operation on database which is already been used by process or some other users.

In order to obtain "Exclusive lock" to perform some critical database operation when someone is already using database you can perform following steps as described below to solve your problem.

Earlier I have blogged in context of restore error, but it is not limited to only restore and since this is very common error you get stuck when you are trying to do some critical database operation i have decided to explain step by step so that it can help me and many others like me who are in same situation. :)


Solution to obtain exclusive locked to perform database operations.


Step 1: Disconnect Connection.
To do so:   File > Disconnect Object Explorer

Step 2: Connect Connection
To do so:  File > Connect Object Explorer

Step 3: Open "New Query" window and run following command
use master
Note: Above command will make your current database to master which is important before we run following sequence of command.

Step 4: Copy and paste following sequence of command in Query window.  Replace the word "MyDatabaseName" with Database name you are trying to get exclusive access.

ALTER DATABASE MyDatabaseName SET SINGLE_USER WITH ROLLBACK IMMEDIATE 

ALTER DATABASE MyDatabaseName SET SINGLE_USER WITH ROLLBACK AFTER 30 

ALTER DATABASE MyDatabaseName SET SINGLE_USER WITH NO_WAIT

ALTER DATABASE MyDatabaseName SET MULTI_USER WITH ROLLBACK IMMEDIATE; 


You are now done and you can now try the command or operation you were trying to perform earlier which was giving you "Database could not be exclusively locked to perform the operation" error. 

Wednesday, October 12, 2011

Service Unavailable Error Sharepoint 2007 After domain controller installation

I have recently create a Sharepoint 2007 Virtual PC Image and everything was working good, till the point i realise that i don't have Sharepoint users to practise. 

In order to create more users in Sharepoint, you need to add users in Sharepoint Active directory.

Since my virtual machine was not having "domain controller" i was unable add more users in Active directory.

Few steps that will be helpful in case you got stuck in similar situation.

Step 1: Update Windows Server 2003 with Service Pack 2

Step 2: Open Run window and type "dcpromo" in run window.  This command will able to start domain controller installation.

Step 3: Follow the wizard and complete domain controller installation.

Now try to open your sharepoint site or sharepoint central administration website.  You will see error "Service Unavailable"

Cause of this error:  Since you have installed domain controller your virtual pc name has changed and as all sharepoint sites are administrator configurable, it will start giving "Service Unavailable" error.  Because your PC name has changed and administrator user settings association is also changed.

Solution - Service Unavailable error
Step 1: Type "inetmgr" on Run window to open IIS (Internet Information Services Manager)

Step 2: Expand ServerName (or your PC Name) and than expand "Application Pools"

Step 3: Now select any of your sharepoint site application pool or shared service application pool, Right click and choose properties


In Shared Service Properties window open Identity tab


On "Identity" tab click on browse button to open "Select User" window



In "Select User" window, type "Administrator" and hit Check Names, If Administrator user is accessible it will underline the Administrator word, than hit OK to close "Select User" window.

You will now notice that your Administrator user name has been updated based on "Domain Controller" name you have choosen.

Step 4:  Retype your password and click OK to close properties window.

Step 5: Repeat steps 3 and step 4 for all your sharepoint sites application pool, including shared service application pool.

Step 6: (If Applicable) Incase any of your sharepoint site application pool is showing stop, than right click application pool and choose "Start" to start application pool for your sharepoint site.

Step 7: Reset IIS.  Type "iisreset" command on Run window to reset IIS, ones all above steps are done.

Now try to open your sharepoint site and sharepoint central administration site, you will now be able to see your sharepoint site up and running.  Incase you tried something else to resolve this problem than please do share your solution. - Thank you :)

Tuesday, June 28, 2011

Internet connection problem on Virtual Machine VM

I was having a Internet connection problem on my virtual machine.  So If you are in same situation this blog post might be helpful to you.

FYI: I am using Oracle VM VirtualBox Manager and OS is windows server 2008.

Step 1: Check Oracle VirtualBox settings.  Click on Network link and check whether attached to is NAT.



Step 2: Click on Network icon from "System tray" and click on "Network and Sharing center".

Step 3: On "Network and Sharing center" window, you will find "Tasks" on left side.  Click on "Diagnose and repair" link.  This will automatically repair your local area connection with parent machine and in turn your Internet access will back on again.

Thursday, April 28, 2011

Error: QueryInterface for interface MyCOM._MyClassFile failed.

Error: QueryInterface for interface MyCOM._MyClassFile failed.
   at MyCOM.MyClassFile.Connect(String& Param1, String& Param2)
   at Company.TestApplication..ctor(Int32 ApplicationId, String p_UserAgencyID, String p_UserView, String p_sMode) in C:\Code\Development\MyWorkNet\TestApplication.vb:line 4884
   at MyApp.MyAppFile.MyMethod1(OracleConnection oConn, OracleTransaction trans, DataRow Record) in C:\Code\Development\MyAppFile.vb:line 349
   at MyApp.MyAppFile.MyMethod2(DataRow Record) in C:\Code\Development\MyApp\MyAppFile.vb:line 308



Cause of error:
This is not the real error.  This is just a abstraction of real error.
You would generally see this error when .exe file is throwing error.


Solution:
This error may occur for multiple reason so you start with

1) Check all necessary software's are installed on PC where you are trying to execute the process which is throwing this error.
Example: If your process needs .Net 4.0 Framework needs to install, then it should be installed.

2) Copy of .exe files and .dll to server and trying to execute process, may result into error.
Example: If you tried to reference COM .dll's in your development solution and build the project.  Then try to do Copy of .exe file and .dll file to another server, that can result into this error, because .dll's are still referencing the path of your development server in most of the case.  If possible try to create a Setup file and make the deployment, this can avoid that error, if that could be the reason.

3) Debug the code by connecting to same database which your process is using.
You will get this error when one of Query is not executing correctly, while code is running.

This error can either occur if stored proc is not proper or trigger is not running properly, or may be data issue, example integrity constraint (MYDBName.FK_Myfield_MyTable) violated - parent key not found

The best way to fix this error is debug the code by connecting to same database (If possible).  You need to come to point where it is throwing error and you would find the exact issue.

Its general tendency to first blame that code is not good, but in this case it has something to do with database rather than code.  I am not sure whether this has helped much, but i am sure this would put you in right direction to explore fix.

Sunday, January 30, 2011

Error: A network-related or instance-specific error occurred while establishing a connection to SQL Server.

Error: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

If you encounter above error, while running your VS.Net, than first thing you should do is to check your web.config file to make sure that connection string is correct.

This problem might occur if you have recently

  • Change your PC Name
  • Installed new sql server instance but have not updated your web.config file with correct instance name.


Example:
Earlier you were using instance name "YourPCName\SQLExpress" but due to new sql server instance installation your instance name changed to "YourPCName\CustomInstanceName".

Below is sample connection string, where text in red is cause of problem.
Data Source=MyPCName\MySQLInstance;Initial Catalog=MyDBName;Integrated Security=True


Solution
Check Connection string in your vs.net solutions, web.config file and correct with new sql server instance name.

Saturday, December 11, 2010

Messages Error 0xc0202009: Data Flow Task 1: SSIS Error Code DTS_E_OLEDBERROR.

I was getting following errors while Importing Excel file to SQL Server

Following is list of error details on Importing Excel 2007 to SQL Server 2008
Error 0xc0202009: Data Flow Task 1: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80004005.
An OLE DB record is available.  Source: "Microsoft SQL Server Native Client 10.0"  Hresult: 0x80004005  Description: "Could not allocate space for object 'dbo.MyTable'.'PK_MyTable' in database 'MyDatabase_1384_8481' because the 'PRIMARY' filegroup is full. Create disk space by deleting unneeded files, dropping objects in the filegroup, adding additional files to the filegroup, or setting autogrowth on for existing files in the filegroup.".
 (SQL Server Import and Export Wizard)

Error 0xc0209029: Data Flow Task 1: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR.  
The "input "Destination Input" (44)" failed because error code 0xC020907B occurred, and the error row disposition on "input "Destination Input" (44)" specifies failure on error. An error occurred on the specified object of the specified component.  There may be error messages posted before this with more information about the failure.
 (SQL Server Import and Export Wizard)

Error 0xc0047022: Data Flow Task 1: SSIS Error Code DTS_E_PROCESSINPUTFAILED.  
The ProcessInput method on component "Destination - MyTable" (31) failed with error code 0xC0209029 while processing input "Destination Input" (44). The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running.  There may be error messages posted before this with more information about the failure. (SQL Server Import and Export Wizard)

Error 0xc02020c4: Data Flow Task 1: The attempt to add a row to the Data Flow task buffer failed with error code 0xC0047020. (SQL Server Import and Export Wizard) 

Error 0xc0047038: Data Flow Task 1: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED.  
The PrimeOutput method on component "Source - 'ip-to-country$'" (1) returned error code 0xC02020C4.  The component returned a failure code when the pipeline engine called PrimeOutput(). The meaning of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing.  There may be error messages posted before this with more information about the failure.
 (SQL Server Import and Export Wizard)


Work Around to deal with this situation
I have observed that from last couple of month my database has grow unexpectedly without my knowledge, and that was main reason for this error.  So if you encounter this problem, don't follow solution blindly otherwise you would never solve root cause of problem.

Do following
  • Try to go through one by one table and check which table had grown unexpectedly.  Tip try from checking table in which rows are inserted automatically.  Example: Errorlog tables and other depends on your application.
  • Ones you find the that table, identify what is causing sudden growth, is it due to code change in application or due to some automatic script run by someone (virus) this problem is causing.  Try to fix that problem.
  • Best approach is to take backup of that table and delete that table and recreate it.  That will fix problem as lot of primary keys are free. 
  • After solving this root cause problem try to apply solution.


Solution
  • Make sure there is enough Hard Disk space where database files are stored on server.
  • Turn on AUTOGROW for file groups.

Now try to Import your Excel File, make sure that you follow all points mentioned in this blog post in order to Import Excel 2007 file to SQL Server.  

Sunday, June 27, 2010

Restore failed for Server - RESTORE HEADERONLY is terminating abnormally

Recently I have upgraded my database from SQL Server 2005 Express to SQL Server 2008 Express, and I have notice on restoring database it started giving me following restore error.

Error Details

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)


------------------------------
ADDITIONAL INFORMATION:


The media family on device 'C:\NorthwindDB.bak' is incorrectly formed. SQL Server cannot process this media family. RESTORE HEADERONLY is terminating abnormally. (Microsoft SQL Server, Error: 3241)


For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=09.00.4053&EvtSrc=MSSQLServer&EvtID=3241&LinkId=20476

Few things you should try before going for solution
This error can occurs due to many reasons but you must ensure following before you start for any solution, it would save your lot of time.

1) Ensure Backup copy of Database is good.
- Take a backup and store on machine where you tried to take backup.
- Now create one dummy database and try to restore that database.
- If you are able to restore that database successfully on machine backup was created, than your backup copy is good.

You should alternately try taking backup using following command

BACKUP DATABASE NorthwindDB
TO DISK='C:\HostingSpaces\MyBackupCopy_NorthwindDB.bak' with FORMAT

If you are able to take backup successfully than Backup copy is good.

2) Ensure Backup copy doesn't get corrupted during dowload.
In my case, I have created a backup copy on Hosting Server, than stored it in .Zip Format, and than try to download it using FileZila, with default settings of filezila transfer type, i.e. Auto.

Till this point everything was going good, but still I was not able to restore DB.

3) Important : Open SQL Query window and check version of your SQL Server.
Run following command and see the output.

Select @@Version

It had given me following output
Microsoft SQL Server 2005 - 9.00.4053.00 (Intel X86) May 26 2009 14:24:20 Copyright (c) 1988-2005 Microsoft Corporation Express Edition on Windows NT 6.0 (Build 6002: Service Pack 2)

After running this command i notice that even though i am using SQL Server 2008 express, it is showing that i am using SQL Server 2005

Cause of Error
Even though I am using SQL Server 2008, but it was connected to SQL Server 2005 instance on the machine i was trying to restore.

Remember:  Restoring Database from lower version to higher version would not give error. i.e. SQL Server 2005 to 2008 would not give error.  But restoring from higher version to lower version will always result in error.  In my case  as i was connected to SQL Server 2005 instance it results me in above error.

You should validate that the instance is the right version by "SELECT @@version".


Solution
You need to fix the connection so it is using the SQL 2008 instance.

Try to run the SQL Server 2008 Express install program again, and during Name Instance configuration, specify a Name Instance with a different name.  Example: MachineName\instancename

After installation, logged in with New Instance name created.

Try to create database, create tables for database and try to run restore again.  It will work this time.

More about Instances
An instance of a SQL Server database is just a named installation of SQL Server. The first one you install on any given machine typically is the default instance, which has no specific name - you just connect to it using the (local) name or the name of the server machine.

SQL Server Express typically installs as a SQLExpress instance - so the instance is called SQLExpress, and you connect to it using (local)\SQLExpress or .\SQLExpress or MyServerMachine\SQLExpress.

SQL Server instances are totally independent of one another, and you can basically install as many as you like - you just have to make sure to use unique instance names for each. But when you run the SQL Server Installation again, it will show you what instances are already installed, and prompt you for a new instance name for a new installation.

Remove sql server 2005 express tools - Installing SQL Server 2008

I was trying to install SQL Server 2008 Express edition, and installation wizard was not allowing me to proceed further unless I remove SQL Server 2005 Express tools.

I tried removing SQL Server 2005 Express tools from Uninstall Program window, but still the same error continues.  In order to fix this you must remove following registry key from registry.

Solution
1) Open Run Menu and type regedit.
2) It will open Registry Editor
3) Now go to following location.
HKEY_LOCAL_MACHINE > Software > Microsoft > Microsoft SQL Server > 90

4) Remove Registry Key 90.

Now try to install SQL Server 2008 and it would work this time.

Thursday, June 10, 2010

ValidateRequest="false" not working in .Net 4.0 (VS.Net 2010)

Recently I have migrated one of my project from .Net 3.5 to .Net 4.0, In other words from .Net 3.5 Project in VS.Net 2008 to .Net 4.0 Project in VS.Net 2010, and I have noticed suddenly my project started giving following error.

Error: System.Web.HttpRequestValidationException
A potentially dangerous Request.Form value was detected from the client (ctl00$CC$txtAnswer=\"... World\r\n\r\nI am doing Testin...\")."} System.Web.HttpRequestValidationException



at System.Web.HttpRequest.ValidateString(String value, String collectionKey, RequestValidationSource requestCollection)
   at System.Web.HttpRequest.ValidateNameValueCollection(NameValueCollection nvc, RequestValidationSource requestCollection)
   at System.Web.HttpRequest.get_Form()
   at System.Web.HttpRequest.get_HasForm()
   at System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull)
   at System.Web.UI.Page.DeterminePostBackMode()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest()
   at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
   at System.Web.UI.Page.ProcessRequest(HttpContext context)
   at ASP.displaypost_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a37c2f81\cfc4c927\App_Web_i2rujncl.9.cs:line 0
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Cause of this error in .Net 4.0 or while working with VS.Net 2010, .Net 4.0 Project
In ASP.NET 4, by default, request validation is enabled for all requests, because it is enabled before the BeginRequest phase of an HTTP request. As a result, request validation applies to requests for all ASP.NET resources, not just .aspx page requests. This includes requests such as Web service calls and custom HTTP handlers. Request validation is also active when custom HTTP modules are reading the contents of an HTTP request.

Solution for ValidateRequest="false" Issue in .Net 4.0

To revert to the behavior of the ASP.NET 2.0 request validation feature, add the following setting in the Web.config file:
<system.web>
<httpRuntime requestValidationMode="2.0" />
</system.web>

Wednesday, June 02, 2010

label does not exist in current context

Error: label does not exist in current context

Scenario:
I have MyPage.aspx which have number of controls, it was working fine, till the point I made heavy changes.  After making lot of changes to MyPage.aspx, when i tried to compile project, it started giving me error: label does not exist in current context.  The problem here was my label control was there on .aspx page, but it was still giving me error at compile time.

Few things I tried which didn't worked

  • Try to switch design view and source view of MyPage.aspx
  • Tried to comment control and try to create same control again.
Cause of Issue:
I have notice even though label control was there on MyPage.aspx it was not their in MyPage.aspx.designer.cs.  So there was something wrong with designer file.

Solution:
  • Delete designer file (Eg: MyPage.aspx.designer.cs)
  • Try to recreate designer file.  
  • delete MyPage.aspx.designer.cs file, now right click on MyPage.aspx and select "Convert to web application" it will create new MyPage.aspx.designer.cs file.
  • At this point when I tried to create designer file i received error, unable to create designer file due to improper html.  After i rectified html on MyPage.aspx and follow the same steps to create designer file, it have created MyPage.aspx.designer.cs
  • Finally my project gets compiled.

Moral of story
I figured out that VS.Net was giving weired error message.  Even though label control was on MyPage.aspx it was throwing wrong error "label does not exist in current context".  Appropriate error message would be something "Resolve improper html..." which would help me to figure out where exactly the problem is... "Don't trust on error message blindly"

Tuesday, March 09, 2010

Solution on RowNum and Union Query Problem

I was trying to create stored procedure for Paging data.

Query which I tried using to fetch data contains union. I want RowNum for this union query and I was trying to do create query as follow.

Select Id,
Title,
ROW_NUMBER() OVER(ORDER BY Title Desc) as RowNum
from
(
select Col1 as Id,Col2 as Title from Table1
union all
select Col1 as Id, Col2 as Title from Table2
union all
select Col1 as Id,Col2 as Title from Table3
) DataSet1

Above query works fine till I perform where clause on RowNum field. As RowNum is not part of subquery, when I tried to perform filter on RowNum field I was getting following error.

Select Id,
Title,
ROW_NUMBER() OVER(ORDER BY Title Desc) as RowNum
from
(
select Col1 as Id,Col2 as Title from Table1
union all
select Col1 as Id, Col2 as Title from Table2
union all
select Col1 as Id,Col2 as Title from Table3
) MyTable
Where
RowNum BETWEEN (1 * 25) + 1 AND (1 * 25) + 25

Error: Invalid column name 'RowNum'

Solution:

In order to resolve this situation I have placed my Query like this.

Select *
From
(
My Query
) MyTable
Where Clause for RowNum filter

In order to resolve Row_Number() function problem with Union Query, I have modified my query to following.

Select *
From
(
Select Id,
Title,
ROW_NUMBER() OVER(ORDER BY Title Desc) as RowNum
from
(
select Col1 as Id,Col2 as Title from Table1
union all
select Col1 as Id, Col2 as Title from Table2
union all
select Col1 as Id,Col2 as Title from Table3
) MyTable1
) MyTable2
Where
RowNum BETWEEN (1 * 25) + 1 AND (1 * 25) + 25

Sunday, February 28, 2010

Error: Code blocks are not supported in this context

Error: Code blocks are not supported in this context
Stack Trace: at System.Web.UI.ControlBuilder.AppendSubBuilder(ControlBuilder subBuilder) at System.Web.UI.TemplateParser.AppendSubBuilder(ControlBuilder builder, ControlBuilder subBuilder) at System.Web.UI.TemplateParser.ProcessCodeBlock(Match match, CodeBlockType blockType, String text) at System.Web.UI.TemplateParser.ParseStringInternal(String text, Encoding fileEncoding) at System.Web.UI.TemplateParser.ParseString(String text, VirtualPath virtualPath, Encoding fileEncoding)
Cause of Error:
This error occurs mainly if your .aspx page, html tags are not closed properly or you have Bad Html tags which could lead to Html Parser error.
Example: I was playing with FreeTextBox, in Html mode. Suddenly a Phone rangup and forget to close Html tag inside FreeTextbox.


<FTB:FreeTextBox ID="FreeTextBox1" runat="Server"
Width="700" Height="500" TabIndex="8" DisableIEBackButton="true">
<Toolbars>
<FTB:Toolbar>
<FTB:InsertHtmlMenu runat="server" Title="Insert Code">
<Items>
<FTB:ToolbarListItem Text="Student" Value="<img
src='<%= Page.ResolveUrl("
~")%&gt;Images/add_buddy.gif' />"
runat="server" />
</Items>
</FTB:InsertHtmlMenu>
</FTB:Toolbar>
</Toolbars>
</FTB:FreeTextBox>

Solution:
Remove Bad Html or rectify Bad Html part from your .aspx page and this error would get resolved.

Sunday, October 11, 2009

Internal server error 500 while running asp.net application

I was getting "Internal server error 500" while running asp.net application.


Cause of Error Code 500
500 Internal Server Error is a general error code and does not reveal any informatino about the actual cause. You need to check the log files for more information i.e. (Event log - Eventviewer). You can also find more details for exact cause of error by disabling "Show friendly HTTP error messages" in your browser.

Solution of Error
Ones you have cause of error, solution would be simple. There could be different error for you, but for me this error was occurring because of following reason.

Event message: Unable to make the session state request to the session state server. Details: last phase='Sending request to the state server', error code=0x80072749, size of outgoing data=0

Exception type: HttpException
Exception message: Unable to make the session state request to the session state server. Please ensure that the ASP.NET State service is started and that the client and server ports are the same. If the server is on a remote machine, please ensure that it accepts remote requests by checking the value of HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\aspnet_state\Parameters\AllowRemoteConnection. If the server is on the local machine, and if the before mentioned registry value does not exist or is set to 0, then the state server connection string must use either 'localhost' or '127.0.0.1' as the server name.

Now,

After checking "Services" in Administrative tools of control panel I found that "Asp.net State Service" was not installed.

I have tried to reinstall asp.net state service again using following command.

c:\Windows\Microsoft.NET\Framework64\v2.0.50727>aspnet_regiis -i

ones asp.net state service is installed you need to start the service and change the start up type option to automatic. Finally my asp.net application started working again.

More details for Win Vista Users

If you are running into above error, than try to check following.

1. Check whether IIS is Installed on your machine? (In Run dialogbox type: Inetmgr)

To Install IIS on Win Vista.

Control Panel > Programs and Features > Turns Windows features on or off

Select Ineternet Information Services from popup dialog and press ok button.

2. Open Services and check whether "Asp.net State Service" is installed? (In Run dialogbox type: services.msc)

To install asp.net state service. run following command from your command prompt and make sure that you are pointing to correct directory.

c:\Windows\Microsoft.NET\Framework64\v2.0.50727>aspnet_regiis -i


ones asp.net state service is installed you need to start the service and change the start up type option to automatic. Finally my asp.net application started working again.

Thursday, October 08, 2009

Restore failed for Server 'my-pc\sqlexpress'

Recently I have upgraded my laptop from 32 bit to 64 bit OS. Most of the thing work good except restoring of Database from my old laptop.


Following is Error I was receiving
===================================
Restore failed for Server 'my-pc\sqlexpress'. (Microsoft.SqlServer.Smo)
------------------------------
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=9.00.4035.00&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Restore+Server&LinkId=20476
------------------------------
Program Location:
at Microsoft.SqlServer.Management.Smo.Restore.SqlRestore(Server srv)
at Microsoft.SqlServer.Management.SqlManagerUI.SqlRestoreDatabaseOptions.RunRestore()
===================================

System.Data.SqlClient.SqlError: Directory lookup for the file "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\dailyfreecode_DATA.mdf" failed with the operating system error 5(Access is denied.).

(Microsoft.SqlServer.Smo)
------------------------------
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=9.00.4035.00&LinkId=20476

------------------------------
Program Location:

at Microsoft.SqlServer.Management.Smo.ExecutionManager.ExecuteNonQueryWithMessage(StringCollection queries, ServerMessageEventHandler dbccMessageHandler, Boolean errorsAsMessages)
at Microsoft.SqlServer.Management.Smo.BackupRestoreBase.ExecuteSql(Server server, StringCollection queries)
at Microsoft.SqlServer.Management.Smo.Restore.SqlRestore(Server srv)

Cause of Error
When you switch from 32 bit to 64 bit, mostly your "Program Files" folder would get changed to "Program Files (x86)" so it is obvious that path of database on old pc doesn't match on new PC and so you would get access denied error. Error is specific to incorrect path while restoring.

Note: Incase if you are creating New database, it is very less likely that you would receive this error.


Solution
Change the path of following two files to appropriate path, while restoring.
1. dbname.mdf file
2. dbname_log.ldf file

More details
Generally you would find that your database files resides in following folder (i.e. Above 2 files)
C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data

But with new change i found that on my PC it was trying to store on following path
C:\Program Files (x86)\Microsoft SQL Server\MSSQL.3\MSSQL\Data

So after changing path appropriately i found that i could able to restore my database.

Most Recent Post

Subscribe Blog via Email

Enter your email address:



Disclaimers:We have tried hard to provide accurate information, as a user, you agree that you bear sole responsibility for your own decisions to use any programs, documents, source code, tips, articles or any other information provided on this Blog.
Page copy protected against web site content infringement by Copyscape