Tuesday, October 23, 2012

How to Detach SQL Database if DB is in Single User Mode


Hi Readers,

I came across a scenario where I need to detach the SQL Database and then take backup of .ldf and .mdf files.
Copy is not possible unless we do not detach the DB. This single user mode is set by SQL Server inorder to prevent corruption of database tables.

You can set the database back to online mode or say multi user mode by executing following commands.

exec sp_dboption 'your db name', 'single user', 'FALSE'

If error still persists, then you need to check which your is having connection with the database and find the particular spid

Inorder to find the connected users execute following command.

select d.name, d.dbid, spid, login_time, nt_domain, nt_username, loginame from sysprocesses p inner join sysdatabases d on p.dbid = d.dbid  where d.name = 'your db name'

This will fetch the users with their $spid. Kill the spids you see using following command.

Kill <spid>  : Here <spid> will be some numeric id like 125, so write Kill 125

again run the 1st command and you will be back to Multi User Mode.

Wednesday, October 17, 2012

10 common difficulties when upgrading/migrating to SharePoint 2010 : Part 1


Hi Readers,
This is the first time I dealt with SP Migration from MOSS 2007 to SharePoint 2010 and have faced lot of issues while working. As per my experience and knowledge, I suggest 10 important points to remember and the difficulties you face while dealing with SP Migration.
1.To Upgrade, or to Migrate ??
2. Migrating Data
3. Migrating from Older Versions of SharePoint
4. Dealing with an Oversized Content Database
5. Wrong Site Template or Site Definition
6. Dealing with Unwanted Data
7. Migrating Content Types
8. Populating Metadata
9. Migrating Files from Outside SharePoint
10. Migrating Data from Exchange Public Folders.

Set the Custom 404 Error Page


Hi,
Have you ever tried setting up the Custom Error Page in SharePoint 2010. For long time I was aware of only below such ways of setting up the Custom Error Page.
1.) Modify the web.cofig file and set the <customErrors> = "ON".
2.) Either you can set it from IIS.
3.) Programmatically set the custom 404 page.
But a another way is a much smarter way i.e. To configure SharePoint Foundation server or SharePoint Server 2010 to point to a custom 404 error Web page via File System.
  1. Log on to the computer that is running SharePoint Server 2010 by using an account that has administrative permissions.
  2. In Windows Explorer, locate the following folder:
    c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\LangID
  3. Create the custom HTML file:
    1. On the computer that is running SharePoint Server 2010, copy the Sps404.html file to a temporary folder.
    2. Rename the Sps404.html file. For example, give the file the following name:
      Custom404.html
    3. Modify the Custom404.html file to suit your needs for a custom 404 error message using an HTML editor.
    Note : In sps404.html you will notice STSNavigate("/_layouts/spsredirect.aspx?oldUrl=" + requestedUrl). You need to modify the line as per you requirement , either create another .aspx page and save it in _layouts folder or can directly point to any .aspx file located on the sharepoint library. i.e. STSNavigate("http://www.mytestsite.com/about/pages/404notfound.aspx");
    4. Copy the Custom404.html file to the %systemdrive% \Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\LangID folder.
    Run the following PowerShell commands from the SharePoint 2010 Management Shell:
    $webapp =Get-SPWebApplication http://<serverUrl>:<port>
    $webapp.FileNotFoundPage = "Custom404.html"
    $webapp.update()

How to get Public key token in Visual Studio 2010


I was developing a custom application for SharePoint and needed to assign it with strong name I assigned a strong name to my project. Now was the time to see the token generated for it. I went ahead and tried to drag that assembly to GAC but I got access denied.

Development machine is Windows Server 2008. Now I tried installing it using GACUTIL but I got the same result even being the administrator of the machine.

Challenge comes in when you want to know the public key token that has been generated for the project so that you can make modification in web.config file.

So here is a solution. We will create an external command that will get us the public key token of the project. So that when that command is clicked we get to see result in command window.

Follow these simple steps. Make sure about spacing and parameters shown here.

Go to Tools menu and then external tools.
Click Add button on which the dialog opens.

Set textbox values like this

Command text box value is

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\sn.exe

Click on OK.

Now when you again click on Tools menu, you get to see our command.

Click on it and we will get the result in output window and from there you get to know the public key token.

I hope this will help while you are developing any custom component in SharePoint.

Slideshow views in Picture Libraries are not allowing end users to delete images


Hello Readers,
Recently I came across an issue in my project where the end users are not able to delete pictures in Picture Library of a SharePoint site which is migrated from 2007 to 2010.
The problem is with the view for the library, not the library itself as the pictures are there and can be opened if I open the library in Windows Explorer.  If I create a new view for the library, the new view works correctly.  If I try to modify the view for the library and then return to the library, I can no longer navigate to subfolders the display only shows the root folder of the picture library.
Here are the steps of what we need to do.
  1. Clone the view "All Pictures" to a view called "Temp" and assigned Temp to be the default view.
  2. Delete the "All Pictures" view
  3. Clone the view "Temp" to "AllItems" assigning AllItems to be the default view.
  4. Delete the view "Temp"
  5. Set  the title fo the AllItems view to be "All Pictures"
Aside from the view GUID everything appears to be identical, but with the links functioning properly.
Here is the below script :
filter Get-Web {
$_.AllWebs
}
Filter get-List {
$_.Lists
}
$viewtitle = 'Slide show view'
$viewinternaltitle = 'Slidshow'
$listtitle
$lists = get-SpSite | Get-Web | Get-List | where-object{$_.basetemplate -eq 'PictureLibrary'} | where-object {$_.title -eq 'BannerImages'}
foreach ($list in $lists){
foreach($view in $list.views){
if($view.title -eq $viewtitle){
$view.clone('Temp',$view.RowLimit,$view.Paged,$view.DefaultView)
$viewid1 = $view.id
}
$list.views.Delete($viewid1)
$list.update()
}
}
foreach ($list in $lists){
foreach($view in $list.Views ){
if($view.title -eq 'Temp'){
$view.clone($viewinternaltitle, $view.rowlimit,$view.paged,$view.defaultview)
$viewid2= $view.id
}
}
$list.views.Delete($viewid2)
$list.update()
}
foreach ($list in $lists){
foreach($view in $list.views) {
if($view.title -eq $viewinternaltitle){
$view.title = $viewtitle
$view.update()
$view.title
break
}
}
}