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

Difference between .Net 4.0 and .Net 3.5, 2.0

.Net Framework 4.0 comes up with some of major changes as compare to previous versions of .Net Framework 3.5 and 2.0

Following are list of Major Changes in .Net 4.0

  • ControlRenderingCompatabilityVersion Setting in the Web.config File 
  • ClientIDMode Changes 
  • HtmlEncode and UrlEncode Now Encode Single Quotation Marks 
  • ASP.NET Page (.aspx) Parser is Stricter 
  • Browser Definition Files Updated 
  • System.Web.Mobile.dll Removed from Root Web Configuration File 
  • ASP.NET Request Validation 
  • Default Hashing Algorithm Is Now HMACSHA256 
  • Configuration Errors Related to New ASP.NET 4 Root Configuration 
  • ASP.NET 4 Child Applications Fail to Start When Under ASP.NET 2.0 or ASP.NET 3.5 Applications 
  • ASP.NET 4 Web Sites Fail to Start on Computers Where SharePoint Is Installed 
  • The HttpRequest.FilePath Property No Longer Includes PathInfo Values 
  • ASP.NET 2.0 Applications Might Generate HttpException Errors that Reference eurl.axd 
  • Event Handlers Might Not Be Not Raised in a Default Document in IIS 7 or IIS 7.5 Integrated Mode Changes to the ASP.NET Code Access Security (CAS) Implementation 
  • MembershipUser and Other Types in the System.Web.Security Namespace Have Been Moved 
  • Output Caching Changes to Vary * HTTP Header 
  • System.Web.Security Types for Passport are Obsolete 
  • The MenuItem.PopOutImageUrl Property Fails to Render an Image in ASP.NET 4 
  • Menu.StaticPopOutImageUrl and Menu.DynamicPopOutImageUrl Fail to Render Images When Paths Contain Backslashes 
Link to find details of all the Major changes in .Net 4.0

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"

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