Fixing database is in use error while restore database from backup

Background

When performing a full restore over an existing database, SQL Backup sometime report that the database cannot be restored because it is currently in use, like shown below

This error shows not only during restore backup, also for drop database or alter database as well.

Workaround

In this situation database administrator needs to disconnect all the connected users from a SQL Server Database to get exclusive access of the Database.In the situation where a full restore is blocked because users are currently connected to the database, the best solution to this problem is to take the database offline prior to running the restore, as this is the easiest way to kill all connections to the database.

Before restore attempt
Database administrator can execute the below mentioned TSQL command to get a Single User access to a database. SINGLE_USER WITH ROLLBACK IMMEDIATE command is used only one user can connect to the database at a time.

use master
alter database DB_NAME set offline with rollback immediate;

After restore
Database administrator can execute the below mentioned TSQL command to give Multiple User access to a database. MULTI_USER command is used any number of users who have rights to connect to the database will be able to connect to the database.

use master
alter database DB_NAME set online with rollback immediate;

So now all authenticated database user can connect to  the database again.

IIS deployment error There is a duplicate scriptResourceHandler section defined

Background

Few days back I was attempting to deploy a .net 3.5 website on the default app pool in IIS7 having the framework section set to 4.0, I get the following error,
There is a duplicate 'system.web.extensions/scripting/scriptResourceHandler' section defined.

Solution

The problem occurs because when you use framework 4.0 the machine config already has some of the section defined that were used in previous asp.net versions. So replace the sectionGroup of your existing web.config with the below configs
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere"/>
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
</sectionGroup>
</sectionGroup>
</sectionGroup>

Another work around is to rebuild website/web application using framework 4, and the problem went away.

How to remove “Click Here To Share” text on images from wibiya

Wibiya web toolbar is free & perfect for blogs, e-commerce sites, small websites. But it comes up with a disturbing option over each images of the site “Click Here To Share”, this prompt user to share this with other social platforms.

If you wish to remove the “Click Here To Share” text, follow following steps:

  • Log into your wibiya.com account.
  • Go to “Edit Toolbar”.
  • Click on the “Smart Share” app.
  • Go to Settings tab.
  • Uncheck “Image Recognition”.
  • Save


Announcement: SocialShare Starter Kit (v1.0) is Released

SocialShare Starterkit v1.0 Relaesed. SocialShare Starter Kit is a kick start application that illustrate a wide range of features that needed to build a social site. And includes features like Status sharing,Blogs,Forums & more. Any one need a lightweight quick solution for his social portal,SocialShare Starter Kit is the savior.SocialShare Starter Kit uses T-4 templates to build logical layers (i.e. DAL/BLL) . The logical layers implemented here are based on Entity Framework 4.0. Its also a good example to learn T4 template and  how to utilize them work with asp.net data bound controls with minimum effort. I am continuously adding and fine tuning the existing feature list and performance. Checkout the app from codeplex SocialShare Starter Kit Home also documentation is available SocialShare Starter Kit documentation

Integrate FB javascript API to your asp.net app to implement FB connect

Hi,

I am going to demonstrate how you can use FB Javascript API to implement Facebook connect applications, as the facebook toolkit for .net is extremely unstable. You have to integrate the below code in your app.

Prerequisite

1)You need a channel.html file , content of that file is only this tag nothing else not even any standard html tags
<script src=”http://connect.facebook.net/en_US/all.js”></script>
2) Top of the page where you are using this code replace your html tag by this tag (required for consistency across browsers)
<html xmlns=”http://www.w3.org/1999/xhtml” xmlns:fb=”http://www.facebook.com/2008/fbml”>

Code

<div>
<fb:login-button perms="email,user_photos"
size="large" length="long">Login with Facebook</fb:login-button>
<div style="display: none;">
<asp:Button ID="fbRegister" runat="server" Text="Ok"
onclick="fbRegister_Click"  />
</div>

<input id="hidEmail" type="hidden"runat="server" />
<input id="hidFirstName" type="hidden"runat="server" />
<input id="hidLastName" type="hidden"runat="server" />
<input id="hidUID" type="hidden"runat="server" />
<div id="fb-root">
</div>
<script src="http://connect.facebook.net/en_US/all.js"
type="text/javascript"></script>
<script type="text/javascript">
FB.init({ appId: 'YOUR_APP_ID', status: true, cookie: true,
xfbml: true, channelUrl: "channel.html" });
FB.Event.subscribe('auth.sessionChange', function(response) {
if (response.session) {
FB.api('/me', function(response) {
    $("#<%=hidEmail.ClientID %>").val(response.email);
    $("#<%=hidFirstName.ClientID %>").val(response.first_name);
    $("#<%=hidLastName.ClientID %>").val(response.last_name);
    $("#<%=hidUID.ClientID %>").val(response.id);
    $("#<%= fbRegister.ClientID %>").click();
   });
    } else {
      // The user has logged out, and the cookie has been cleared

}

});
function LoginWithFB() {
       $("#<%= fbRegister.ClientID %>").click();
}
</script>
</div>

Replace YOUR_APP_ID with your application id that you get during application registration with facebook. You can download sample code from here[^]

whats the difference in Page class function ResolveURL vs ResolveClientURL

The .NET Page class contains two methods ResolveUrl and ResolveClientUrl  which are at first glance looks same.They both took same relative url and returns browser friendly URl. So why 2 function to do the same job?
Though their functionality is same but their way of returning client brower relative url makes the huge difference.ResolveClientUrl returns a path relative to the current page which user currently browsing, and ResolveUrl returns a path relative to the site root that is configured as root in IIS.

Lets Consider this structure
ROOT
–App_Themes
–Images
—-mypic.png
–MyAccount
—-default.aspx

Now from above example root of the IIS directory is ROOT, and all other directory is under this root. Now from MyAccount->default.aspx tries to access Images->mypic.png. ResolveUrl will do top to bottom parsing to find the resource, on other hand ResolveClientUrl will do bottom up parsing to find the same resource.
Function: Page.ResolveUrl(“~/Images/mypic.png”)

Returns: “/Images/mypic.png”

Function: Page.ResolveClientUrl(“~/Images/mypic.png”)

Returns: “../Images/mypic.png”

Difference betwwen this two is very visible if you hoste your web app under a shared hosting under a subdomain.For example you host your MY_SITE app under www.example.com subdomain,
and your physical file path is

example.com\www\MY_SITE under IIS directory.
So under this you placed your file structure given above. Now for any link if you set
Page.ResolveUrl(“~/MyAccount/default.aspx”),

watch out the URL in browser status bar you will see
www.example.comwww/MY_SITE/MyAccount/default.aspx ,

because ResolveUrl will parse from top root domain for this resource, so it took full path from root for that specific resource. On other hand ResolveClientUrl can solve this problem, this will parse from browsers present location to up towards the root so find the specific resource path.

Simple solution to the crazy Visual Studio problems

On my daily development life ofen I face some strange problem. Then I have to google out and find the solution, next time same problem arise again and guess what I forgot the solution !!.I guess this happen to every .net developers. So this time I decided to put all solution in one place so I can find those easily. I want to share this with you all. I will update this post every time I will face a problem and find a solution. So keep an eye on my feed.

Error Description:

Can’t create ANY new project or can’t add any project to existing solution. I tried, web, console, services, and no luck. Visual Studio 2008 giving me this error

“Could not load file or assembly CustomMarshalers, Version=2.0.0.0″

Solution:
For some reason, CustomMarshalers was not installed/ uninstalled/corrupted into the GAC(Global Assembly Cache). Install/reinstall again.
c:\>gacutil -i C:\Windows\Microsoft.NET\Framework\v2.0.50727\CustomMarshalers.dll

Implementing Yahoo Contact Reader Using Asp.NET

Mail contact reader became an exciting feature as new social sites are being introduced or email-campaign becomes a key success factor for online business. I have work on several projects where app facilitates email contact reading from user’s personal mailing account. Most of the users use free mailing services like Gmail/hotmail/AOL/yahoo and list goes on. Most of time I used third party solutions (that saves lots of my time) and those works pretty well. But those solutions I used are not easy to customize according to my needs. So this time I have decided to find myself for a stable solution and I started with very popular mail service Yahoo!. This article will be helpful for those people who are working with contact reader app and for those who are interested to work with Yahoo! API.

Check out my new article on
http://www.codeproject.com/KB/aspnet/yahoo-contact-reader.aspx

Developing facebook connect application using asp.net

Check out my new post @code project. This is a step by step approach for developing a facebook connect application with asp.net.
http://www.codeproject.com/KB/aspnet/fb_connect_asp_net.aspx
Enjoy!!

Useful IIS commands for programmers

In this short article I want to list some IIS commands that are very commonly used by developers.When needed I googled the commands each time. So intead of google each time I collected the commands and put those in same place.Some of them is listed below

Re-Register IIS

aspnet_regiis.exe -i

To restart IIS

iisreset /noforce computername

To disable restart of IIS

iisreset /disable
Create a virtual Web directory

type the following command from a command prompt:

Mkwebdir -c ComputerName -w “WebSiteName” -v DirectoryName,DriveLetter:\FolderName

Start a Virtual Site Without Interrupting the Entire Web Service

adsutil START_SERVER W3SVC/Server#

list of the other commands

  1.     chaccess
  2.     contftp
  3.     contsrv
  4.     contweb
  5.     dispnode
  6.     disptree
  7.     findweb
  8.     mkw3site
  9.     mkwebdir
  10.     pauseftp
  11.     pausesrv
  12.     pauseweb
  13.     startftp
  14.     startsrv
  15.     startweb
  16.     stopftp
  17.     stopsrv
  18.     stopweb
  19.     synciwam

To view the list of running IIS appications

iisapp

Follow

Get every new post delivered to your Inbox.

Join 69 other followers