Thursday, December 19, 2013

Forcing InfoPath forms to load in web browser view - SharePoint

Scenario and solution:
You have a page that containd web part views into your forms library (that contains forms that can be filled out in a browser). The problem here is that if you or your client has InfoPath installed on their computer, everytime they click the link the form will try and open in their InfoPath client; prompting them for authentication.
If the client goes to the forms library itself and clicks on a InfoPath form the form opens in the browser no problem, why? The answer is in the url, try this:
  • Go to the forms libray and click on a form, check the URL; it should look something like this: "http://site.example.com/subsite/_layouts/FormServer.aspx?XmlLocation=/subsite/formLibrary/formName.xml&Source=http%3A%2F%2Fsite%2Eexample%2Ecom%2Fsubsite%2FformLibrary%2FForms%2FMyView%2Easpx&DefaultItemOpen=1
  • No go the web part and click the same form, check the URL (in the browser status bar): http://site.example.com/subsite/formLibrary/formName.xml
  • Note that the URL is completely different which is why I think the form does not want to open in the web browser view.
Now, to fix the URL in the web part we are going to need to convert that web part to a data view web part through sharepoint designer:
  • Open one of your forms from the form library and copy the URL into NotePad.
  • Open the offending page containing the web part in sharepoint designer.
  • Go to design view, right click the web part and select convert to xslt data view.
  • Select the ">" next to the data field that you want displayed as the link to the file and then select the option to format the text as a hyperlink.
  • In the new dialog box, in the location text box paste the URL from NotePad.
  • Replace the following text: "XmlLocation=/subsite/formLibrary/formName.xml" in the location text box with "XmlLocation={@FileRef}" this tag indicated the full URL to the form.
  • Save
Open the web part page and click the link in the web part: the form now opens in a web browser!

Tuesday, November 12, 2013

Auto-Generating Filenames for InfoPath Forms

http://claytoncobb.wordpress.com/2009/06/20/auto-generating-filenames-for-infopath-forms/


Auto-Generating Filenames for InfoPath Forms – I see this topic come up a LOT on forums all over the place, so instead of continuing to answer the question time and time again, I am going to post a quick blog entry showing the steps.  I think this stuff is fairly simple, but it just doesn’t pop into your head initially.  Once you see it and understand it, you’ll think it’s simple, too.  Keep in mind that I focus entirely on SharePoint-based InfoPath forms and for the most part BROWSER-ENABLED forms.  So, it’s possible and likely that all concepts explained here will work for non-browser forms and non-SharePoint forms, but just remember that my perspective is mostly browser-enabled.  The basis for this topic is that the standard method for submitting InfoPath browser-enabled forms is for the user to click Save at which point the user is prompted to give a filename along with choosing to allow overwrite.  I really dislike this feature, because users have no concept of proper naming convention for the most part, and there’s no way to guarantee they create a unique or meaningful filename.  I also just don’t like the user getting prompted.  I prefer for the user to just click a button that saves the file to SharePoint with a dynamically-defined filename, closes the form, and takes the user back to the forms library.  Ok, so how do we do ensure these few things:
  • The filename must be unique
  • The filename must persist through subsequent edits of the form without the user having to do anything
  • The built-in toolbar buttons must be hidden
  • A custom button must be created to do it all
Here are the steps:
  1. Create the field for storing the filename
  2. Create the Submit data connection that uses this field
  3. Disable the browser-based toolbar functions
  4. Create the custom submit button
Create a hidden field for storing filename
Create a strFilename field (Text).  Do not set any conditional formatting, rules, or data validation on this.  Add it to the canvas for now and make it read-only (Fig 1).  This will be visible for testing purposes only.

Fig 1 – Create hidden field named strFilename
Create a Submit data connection that uses the strFilename field for dynamically creating the filename
Create a SUBMIT data connection in your form template that connects to the Form Library where the form resides.  Put in the URL of your Form Library for the “Document Library” field, and choose the strFilename data element for “File name” field by using the fx button.  Check the box for “Allow overwrite if file exists” (Fig 2).
Fig 2 – Creating the Submit data connection for the Form Library
Disable toolbar options
Click Tools > Form Options > Browser.  Uncheck Save, and Save As (Fig 3).  Submit should be grayed since it has not been configured.  If it has been configured, be sure it is unchecked.  Update should be unchecked by default, so leave it.  I personally uncheck “Views,” since I use views to dynamically route people to certain information based off their identity or the form’s workflow status, but it’s up to you.  If your form is not browser-enabled, use the Open and Save menu in Form Options to uncheck Save and Save As.
Fig 3 – Disabling toolbar functions for Browser-Enabled Forms
 Create the custom Submit button
Drag a button control to your canvas and double-click it to get to its properties.  Change the display name to “Submit” or whatever you prefer, then click Rules.  You want to add two rules, each with one condition (Fig 4).
 
Fig 4 – Custom Submit button with two rules
The first rule allows you to Edit the existing form without changing strFilename, then close it (Fig 5).
  • Set a condition rule to have one condition stating that strFilename is not blank.
  • Add two actions in this order:
    • Submit to your SharePoint Library Submit data connection
    • Close
Fig 5 – Editing the form with the submit data connection
Here, we are simply submitting the form back to the library in a manner that will not change any metadata and will overwrite the existing file of the same name.  This is the whole reason for the strFilename field.  We do not want the strFilename to be recreated each time the form is edited.  This rule is placed before the Submit rule for the same reason as stated above.  We need to check first to see if the form has already been submitted.  If so, then we submit using the current strFilename.  If not, then we skip this rule.
The second rules will Submit the current form only if it is brand new and after dynamically creating the strFilename, then it closes the form.
  • Set a condition rule to have one condition stating that strFilename is blank.
  • Add three actions in this order:
    • Set the Value of strFilename (Fig 6) to the concatenated string combining userName() with now().  The formula is concat(userName(), now()).  The Xpath is concat(xdUser:get-UserName(), xdDate:Now()).  Note: I add a text hyphen in the middle to make it a little easier to read, but that’s up to your discretion.
    • Submit to your SharePoint Library Submit data connection
    • Close
Fig 6 – Setting the dynamic filename prior to submission
Here, we are submitting the form to the form library for the first time.  This is why we first dynamically create the strFilename, because the Submit data connection uses this field to create the filename in SharePoint.  We only want to do this step upon first submission, so that is why this rule only runs if the strFilename is blank.  Doing this rule last keeps us from double-submitting, because the Edit rule would run right after the Submit rule due to its condition being met (strFilename is not blank).  You can of course choose any concatenation formula you want as long as it is unique.  This particular formula can only create a non-unique filename if the same user submits two separates forms (two browser forms open simultaneously) at the same EXACT second.
Publish your form to a new form library, and set that library to Display in Browser (Advanced Settings).  Click New to create a new form (Fig 7)
FN07
 
Fig 7 – A new form before submission
Click submit, and it should take you back to the library with no prompts or delays.  You will see a new form with a unique filename (Fig 8).  The now() function gives the date AND time separate by the letter “T.”
FN08
 Fig 8 – Newly-created form has unique filename
Click on that new form and notice that the strFilename field has been populated with the same info you saw for the filename in the library (Fig 9).  This field is actually populated FIRST when you submit, because it forms the basis for the filename in the Submit data connection.  Click submit again and notice that the existing file has been changed rather than a new file being created.
FN09
Fig 9 – strFilename field is populated with the dynamic, unique filename
Reference links for related articles:
InfoPath Submit Error- A value in the form may be used to specify the file name - You may be getting this error.   This blog post helps explain why, and my blog post helps explain how to overcome it.

Tuesday, October 22, 2013

Create a SharePoint Custom Action to Zip and Download a Document Set

Here’s the URL to the built-in document set downloader page: {SiteUrl}/_layouts/DocSetExport.aspx?List={ListId}&ID={ItemId}. It takes in the GUID of the list and the ID of the document set. Here’s an example: http://sharepoint2010/sites/docman/_layouts/DocSetExport.aspx?List={4E2D11F5-7500-476A-B001-62A7BF92FD50}&ID=10
Adding a Custom Action to the Document Set List Item Menu using SharePoint Designer
To add a custom action, open the site in SharePoint Designer and navigate to the document set list. Add a new list item menu custom action:
image
Provide a Name, Description, and Navigate to URL:
image
Save the custom action, and test it:
image
image
I want to mention that there is a drawback to this approach. The custom action will show up for every list item, not just the document set. The list item menu will appear on documents in the document set as well:
image
Adding a Custom Action to the Document Set Ribbon using SharePoint Designer
We can also use SharePoint Designer to add a button to the document set ribbon, but the user experience isn’t ideal. You’re better off creating this custom action in a sandboxed (or farm) solution. The reason for this is that custom actions created in SharePoint Designer operate on a list item, so the user has to select a list item before the ribbon button lights up to zip and download the document set. Understanding the limitations, here’s how to do it:
Add a new view ribbon custom action:
image
Enter a Name and Description as before, but this time use JavaScript for the custom action. We need script to get the ID of the document set rather than the ID of the selected item. Enter the following for the Navigate to URL:
javascript:function getQS(key){var regex=new RegExp('[\\?&]'+key+'=([^&#]*)');var qs=regex.exec(window.location.href);return qs[1];}var url='{SiteUrl}/_layouts/DocSetExport.aspx?List={ListId}&ID='+getQS("ID");window.location.href=url;
Now when you select a document the zip and download button lights up:
image
Adding Custom Actions to the Document Set List Item Menu using a Sandboxed Solution
Next, I’ll show you how to create a sandboxed solution that provides a better user experience and is reusable across sites. The solution deploys both the list item and document set ribbon and scopes the custom action to just the document set content type. To get started, create a new empty SharePoint project in Visual Studio 2010. Add a feature and name it DocSetDownload. Add a new Elements item named CustomActions. Add the following to the Elements.xml file
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
    Id="DocSetDownload.Ribbon"
    Title="Zip and Download"
    Description="Zip all documents in this document set and download."
    RegistrationType="ContentType"
    RegistrationId="0x0120D520"
    Location="CommandUI.Ribbon">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
          Location="Ribbon.ManageDocumentSet.MDS.Share.Controls._children">
          <Button
            Id="Ribbon.ManageDocumentSet.MDS.Share.Controls.DocSetDownload"
            Sequence="20"
            Command="Ribbon.ManageDocumentSet.MDS.Share.DocSetDownload"
            Alt="Zip and Download"
            Image16by16="images/DocSetDownload16x16.png"
            Image32by32="images/DocSetDownload32x32.png"
            LabelText="Zip and Download"
            ToolTipTitle="Zip and Download"
            ToolTipDescription="Zip all documents in this document set and download."
            TemplateAlias="o1" />
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
          Command="Ribbon.ManageDocumentSet.MDS.Share.DocSetDownload"
          EnabledScript="true"
          CommandAction="javascript:
          function getQS(key){
            var regex=new RegExp('[\\?&amp;]'+key+'=([^&amp;#]*)');
            var qs=regex.exec(window.location.href);
            return qs[1];
          }
          var url='{SiteUrl}/_layouts/DocSetExport.aspx?List={ListId}&amp;ID='+getQS('ID');
          window.location.href=url;
          " />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>
  <CustomAction
    Id="DocSetDownload.EditControlBlock"
    Title="Zip and Download"
    Description="Zip all documents in this document set and download."
    RegistrationType="ContentType"
    RegistrationId="0x0120D520"
    Location="EditControlBlock">
    <UrlAction Url="{SiteUrl}/_layouts/DocSetExport.aspx?List={ListId}&amp;ID={ItemId}" />
  </CustomAction>
</Elements>
Next, add a Module item named images to the project and add the custom images for the ribbon:
image
Deploy and test the solution. You’ll see the custom action on the ribbon:
image
The custom action will also appear on the list item menu:
image

http://blogs.msdn.com/b/johnwpowell/archive/2012/01/21/create-a-sharepoint-custom-action-to-zip-and-download-a-document-set.aspx

Monday, October 21, 2013

Update Hyperlink Field in SharePoint with PowerShell

I want to change the URL in list item from https://Texas.com to https://ta.com using Powershell script

1) copy & paste (change the URLs and Listnames and field) the below script and name it with extension .ps1 (ex: ItemURLChange.ps1)


#Add-PSSnapin Microsoft.SharePoint.PowerShell

$siteUrl = "http://sharepoint/SiteCollection/SiteName"
$webName = “SiteName”
$listName = "Name of your list"
$spSite = new-object Microsoft.SharePoint.SPSite($siteurl)
$spWeb = $spSite.OpenWeb($webName)
$spList = $spWeb.Lists[$listName]

foreach($Item in $spList.Items )
{
$ofldurl= new-object Microsoft.SharePoint.SPFieldUrlValue($Item["URL"])

$ofldurl.URL = $ofldurl.URL.Replace("Texas", "ta")
$ofldurl.Description = $ofldurl.Description.Replace("Texas", "ta")

$item["URL"] = $ofldurl
$item.update()
}

$spWeb.Dispose()

2) Open the Powershell command and run using the below command

PS C:\temp> ./ItemURLChange


http://www.sharepointed.com/2011/09/09/update-hyperlink-field-in-sharepoint-with-powershell/

Monday, September 23, 2013

Email / Phone validation in SharePoint 2010 Column validation

=(LEN(LEFT([Email Address],FIND("@",[Email Address])-1))>0)+(LEN(RIGHT([Email Address],LEN([Email Address])-FIND(".",[Email Address],FIND("@",[Email Address]))))>0)+(LEN(MID([Email Address],FIND("@",[Email Address])+1,FIND(".",[Email Address],FIND("@",[Email Address]))-FIND("@",[Email Address])-1))>0)+(ISERROR(FIND(" ",[Email Address]))=TRUE)=4

--------------------
Phone Validation (example: 123-456-7896x486):

=AND(LEN([Phone Number])=16,IF(ISERROR(FIND("",[Phone Number],1)),FALSE,(FIND("",[Phone Number])=1)),IF(ISERROR(FIND("-",[Phone Number],4)),FALSE,(FIND("-",[Phone Number],4)=4)),IF(ISERROR(FIND("-",[Phone Number],8)),FALSE,(FIND("-",[Phone Number],8)=8)),IF(ISERROR(FIND("x",[Phone Number],13)),FALSE,(FIND("x",[Phone Number],13)=13)),IF(ISERROR(1*CONCATENATE(MID([Phone Number],1,3),MID([Phone Number],5,3),MID([Phone Number],9,4),MID([Phone Number],14,3))),FALSE,AND(1*CONCATENATE(MID([Phone Number],1,3),MID([Phone Number],5,3),MID([Phone Number],9,4))>1000000000,1*MID([Phone Number],1,3)<>911,1*MID([Phone Number],5,3)<>911,1*MID([Phone Number],5,3)<>555,1*MID([Phone Number],14,3)<>911)))

Wednesday, July 10, 2013

Specify page to redirect to when adding a item (new form or edit form)

1. Open your Newform.aspx page
2. Add a CEWP. Type following line in your site url
(http://serverip/Lists/Test/NewForm.aspx?&toolpaneview=2 )
3. Paste below script in source code
<script>
function PreSaveAction() {
var srcUrl=GetSource();
var newSrcUrl = "http://www.google.com";
var i = aspnetForm.action.lastIndexOf(srcUrl);
aspnetForm.action = aspnetForm.action.substring(0,i) + newSrcUrl ;
return true;
}
< /script>


---------------------------------

JQuery for Cancel button:

Use the following jQuery code to override the behavior of the cancel button:


    $(function() {
      $('input[value=Cancel]').click(function() {history.go(-1);});
    });

Thursday, June 13, 2013

Rename button Text in NewForm.aspx or EditForm.aspx

Rename button Text in NewForm.aspx or EditForm.aspx in SharePoint  Lists
<script type="text/javascript">

function changeFinish()
{
var inputs = document.getElementsByTagName("input");
for(i = 0; i<inputs.length; i++)
{
if(inputs[i].type == "button" && inputs[i].value == "Save")
inputs[i].value = "Submit";
}
}


_spBodyOnLoadFunctionNames.push("changeFinish");

</script>

Sunday, June 9, 2013

Clear SharePoint Desinger Cache




Sometimes SharePoint Designer loses touch with reality - it demands to check out files that are not checked in, refuses to check in other files and generally misbehaves. This demeanor is sometimes accompanied by this error message:
"Cannot perform this operation. The file is no longer checked out or has been deleted."
Simply put, SharePoint Designer is out of sync with SharePoint and you have to delete its cache in order to rebuild it. The cache is composed of these 2 folders:
  • %APPDATA%\Microsoft\Web Server Extensions\Cache
  • %USERPROFILE%\AppData\Local\Microsoft\WebsiteCache
Just delete their contents and you are done.

C:\Documents and Settings\%LocalUser(Ravi)%\AppData\Local\Microsoft\WebsiteCache

Thursday, May 16, 2013

Hiding Sharepoint 2010 Ribbon in New Form.aspx with Jquery

//using below script you can hide entire ribbon
//$(“div.’s4-ribboncont:contains(‘Spelling’)”).parent(‘div’)[0].style.display = “none”;
//using below script you can hide ribbon but the dark blue background will remain visible
//$(“div.ms-cui-tabContainer:contains(‘Spelling’)”).parent(‘div’).hide();
//using below script you can hide save Button in Ribbon
//$(“span.ms-cui-ctl-largelabel:contains(‘Save’)”).parent(“a”).hide();
//using below script you can hide past Button in Ribbon
//$(“span.ms-cui-ctl-largelabel:contains(‘Paste’)”).parent(“a”).hide();
//using below script you can hide Cancel Button in Ribbon
//$(“span.ms-cui-ctl-largelabel:contains(‘Cancel’)”).parent(“a”).hide();
//using below script you can hide Attachment Button in Ribbon
//$(“span.ms-cui-ctl-largelabel:contains(‘Attach’)”).parent(“a”).hide();
//using below script you can hide Cut Button in Ribbon
//$(“span.ms-cui-ctl-mediumlabel:contains(‘Cut’)”).parent(“a”).hide();
//using below script you can hide Copy Button in Ribbon
//$(“span.ms-cui-ctl-mediumlabel:contains(‘Copy’)”).parent(“a”).hide();
//using below script you can hide Spelling Button in Ribbon
//$(“span.ms-cui-ctl-largelabel:contains(‘Spelling’)”).parent(“a”).hide();
//using below script you can hide
//$(“span.ms-cui-ctl-a1Internal”).parent(“a”).hide();
//using below script you can hide Menu Label Action in Ribbon
//$(“span.ms-cui-groupTitle:contains(‘Actions’)”).hide();
//using below script you can hide Menu Label Commit in Ribbon
//$(“span.ms-cui-groupTitle:contains(‘Commit’)”).hide();
//using below script you can hide Menu Label Clipboard in Ribbon
//$(“span.ms-cui-groupTitle:contains(‘Clipboard’)”).hide();
//using below script you can hide Menu Label Spelling in Ribbon
//$(“span.ms-cui-groupTitle:contains(‘Spelling’)”).hide();
//using below script you can hide Menu Separator in Ribbon
//$(“span.ms-cui-groupSeparator”).hide();

http://sharepointinfoit.wordpress.com/2011/10/07/hiding-sharepoint-2010-ribbon-in-new-form-aspx-with-jquery/

Tuesday, April 30, 2013

Customizing the Request Access page in SharePoint 2010

This article is Based on below URL :
http://oszakiewski.net/eric/customizing-the-access-request-page-in-sharepoint-2010


Our organization, like many others, handles access requests for all applications through our IT Support desk. Additionally, documentation is required and must be approved by the user’s department manager before the access can be granted. After just recently migrating the entire company’s intranet over to SharePoint 2010, I wanted to allow users to request access, so I made sure the Manage Access Requests was selected by default for all resources. However, within a week of moving it over I’m getting requests for all sorts of things in my inbox every day, even from our kiosk service accounts in the employee break room or at terminals, which are both locked down intentionally. I don’t mind the access requests, but there needs to be a consistent way of handling requests that complies with our internal standards.
I did some research into the Access Request email message that comes from SharePoint, thinking maybe I can modify the timer job, workflow, email content, etc. Nothing. In fact, the very same discussion is held in a TechNet article located here. Bummer, this would have been ideal.
So what’s the next best step? Modify the reqacc.aspx file in C:\program files\common files\microsoft shared\web server extensions\14\template\layouts.
Here’s what the original page looks like:

** WARNING: Make a copy of the original file BEFORE modifying! Making changes to the layouts folder in SharePoint is always at your own risk! If for any reason your changes are unsuccessful, you can always delete that file and place the copied original back in the folder to restore functionality!
That being said, here’s what I did to create a custom Request Access page:
1. Navigate to your layouts folder, typically located at c:\program files\common files\microsoft shared\web server extensions\14\template\layouts
2. Make a copy of the reqacc.aspx file and put it somewhere safe. Make NO changes to this copied file!
3. Open the other reqacc.aspx file (not the copy) in your editor of choice.
4. Near the bottom, locate the following section of code:
<td id="RoleDescription" class="ms-descriptiontext"><br/><SharePoint:EncodedLiteral runat="server" text="<%$Resources:wss,reqacc_entermsg%>" EncodeMethod='HtmlEncodeAllowSimpleTextFormatting'/></td>
< /tr>

This is the section of the page that says “Type your request, and then click Send Request.” Deleting it breaks the page because SharePoint is looking for specific elements in the page, so all I did was hide it by adding the following CSS attribute:
<td id="RoleDescription" style="display:none" class="ms-descriptiontext">
This will override the CSS class settings and hide the element altogether. Do the same thing to the textarea below it, to prevent users from entering in anything:

< td class="ms-descriptiontext">
< textarea name="txtareaMessage" id="txtareaMessage" rows="0" cols="0" class="ms-descriptiontext" runat=Server></textarea>
< /td>

This is the textbox that says “Supply a description of the action you were taking and the URL you were trying to reach.” I hid the entire element by adding the same style attribute like so:
< td class="ms-descriptiontext"
style=”display:none”>
<textarea name="txtareaMessage" id="txtareaMessage" rows="0" cols="0" class="ms-descriptiontext" runat=Server></textarea>
< /td>

5. If you want to enter a custom message or instructions for the user to follow, I put that in place of the input button in the next table row below the textarea, located here:

< td>
< input type="submit" value="<%$Resources:wss,reqacc_sendreq%>" id="btnSendRequest" accesskey="s" runat="Server"/>
< /td>

Here is a sample of what I replaced it with:

< td>
< font size="4pt">To request access, please fill out a User Access Request Form located <a href="internal link to InfoPath form">here</a>. Make sure the resource you need access to is listed in the form, including the URL listed above.</font>
< /td>

Save the file and the changes are immediate. The end result will look something like this:
You could theoretically change this page however you want, but I liked the existing simplistic layout, it got to the point and provided the end user with enough information. Of course, custom application pages can be made and used in SharePoint nearly anywhere. Hope this helps!

Tuesday, April 23, 2013

HTML Formatter

Formats a HTML string/file with your desired indentation level. The formatting rules are not configurable but I think it provides the user with the best possible output.
Note that the formatter will keep spaces and tabs between content tags such as divs and spans as it's considered to be valid content.
*Files bigger than 1 meg will be formatted to a new window.

Good tool for HTML format:

http://www.freeformatter.com/html-formatter.html

Sunday, April 7, 2013

How to transfer logins and the passwords between SQL Servers

http://sqlserver.in/blog/index.php/archive/category/administration/database-migration/

Step-by-Step Guide to Configuring Database Mirroring in SharePoint 2010

I was looking up some material on database mirroring, and I could find a good step-by-step post on setting up such functionality. So here it is!
Read these posts before you begin - you should really understand the concepts if you are to undertake this, especially in a production environment.
http://technet.microsoft.com/en-us/library/dd207314.aspx
http://blogs.technet.com/b/wbaer/archive/2010/05/03/database-mirroring-in-sharepoint-2010.aspx
http://www.sharepointbandit.com/2010/08/configure-database-mirroring-on.html
My SQL instances are based on the SQL Server 2008 R2 Standard SKU, but they we're upgraded from SQL Express 2008 R2, hence the sqlexpress names:
Mcm-server-1\sqlexpress (Primary) & Mcm-server-2\sqlexpress (Mirror)
SQL Service Account: mcm\svc_sql
Database to sync: WSS_Content_ProductionDB
For mirroring to work, the versions of SQL must be the same on both servers.
1. Configure permissions on the mirror server according to the details from the technet article:
  • The Central Administration application pool account should be a member of the dbcreator and securityadmin fixed server roles.
  • All application pool accounts, the default content access accounts, and any accounts required for service applications should have SQL Server logins, although they should not be assigned to SQL Server fixed server or fixed database roles.
  • Members of the Farm Administrators SharePoint group should also have SQL Server logins and should be members of the same SQL Server roles as the Central Administration application pool account.
2. Ensure that no firewall is blocking connectivity between the servers. In particular, you will create a TCP connection over a port, by default 5022.
3. Make sure that the database is in the Full recovery model
clip_image001
4. Perform a FULL backup of the database you are going to mirror:
clip_image002
5. Place the backup to a place where the mirror server can access it. I dropped it on a network share:
clip_image003
6. Restore the database on the mirror SQL Server. Notice how I have referenced the UNC path - SQL's interface here is not the best, you have to type in the location and file name for it to find the backup. See the next point before you proceed.
clip_image004
clip_image005
7. On the restore page you MUST select a RESTORE WITH NORECOVERY under the Options menu. This is required for DB mirroring to work:
clip_image006
8. Assuming your restore was successful, the database will always show as "Restoring…":
clip_image007
At this stage you could proceed with setting up mirroring.
9. Go to the Mirroring settings page on the Primary server's database in the Database Properties section. Go ahead and click Configure Security…
clip_image008
10. Run through the wizard. Select to set up a witness server if the situation requires one. The wizard will ask you to configure the endpoints for communication on all instances. Make sure the port is open over TCP and that you select to encrypt the data.
clip_image009
clip_image010
11. The next screen lets you specify database mirroring service accounts. In my case I left them blank as all SQL instances are running under the same service account. Read this article for more info on service accounts: http://msdn.microsoft.com/en-us/library/ms189434.aspx
clip_image011
12. Continue the wizard and your endpoints will get created:
clip_image012
13. Click close and you will get the next message with some information. Click the Start Mirroring button and hopefully it works (:
clip_image013
14. You should get no errors and your Mirroring page should look similar to mine. (I postponed the configuration of my witness):
clip_image014
15. Your databases will indicate that mirroring is configured:
clip_image015
clip_image016
(ignore the ArchiveDB in the screenshot, I had to set it up twice...)
16. To check if it is all working you could use the "Launch Database Mirroring Monitor" tool:
clip_image017
This will provide you with information, which is near real time. I uploaded a large document on the Primary server in SharePoint and refreshed the tool a few times:
clip_image018
Now it is time to tell SharePoint that we have a failover database set up. SharePoint must know this to change its connection string when the mirrors swap. To do this we must use PowerShell:
$db = get-spdatabase | where {$_.Name -eq "WSS_Content_ProductionDB"}
$db.AddFailoverServiceInstance("MCM-SERVER-2\sqlexpress")
$db.Update()
In Central Administration you will see the setting populated. Read Bill Baer's post on how exactly this setting is used.
clip_image019
As a final test, go back in SQL, go on the mirroring page and click the Failover button. This will ultimately swap the roles of your two databases.
clip_image020
Click it and make sure SharePoint is still working for you! Hope this helps!

Ref: http://www.sharepoint.bg/radi/post/Step-by-Step-Guide-to-Configuring-Database-Mirroring-in-SharePoint-2010.aspx

***********************************************************************

Here is the detailed step by step implementation of Database Mirroring with screen shots. Note that I have shown here is a High Protection Mirroring scenario.
Here we are setting up a synchronous operating mode.
Step 1
Create MirrorDB in the source database (called as Principal database), for which we are going to start mirroring.
mirror1
mirror2
Step 2
Create a backup of the MirrorDB in the source SQL Server (Principal database) & restore it in the destination server with the same name. Make sure to restore the database with NORECOVERY. The destination server MirrorDB is called as Mirror database.
mirror3
mirror4
mirror5
mirror6
mirror7
mirror9
Step 3

As shown in the below screen, right click on the database, select properties & select Mirroring. Select Configure Security to configure mirroring for the required database.
Follow the screen shots as given below.

Note that here I do not have a Witness server, & hence select “NO” for include Witness server option.
mirror10
mirror11
mirror12
mirror13
Step 4
Select the Mirror Server Instance as shown below & click connect. Here we have to specify the destination, i.e. Mirror database server’s credentials to connect.
mirror14
Step 5
Leave service accounts for both Principal & Mirror blank, follow the remaining screen shots.
mirror15
mirror16
mirror17
Step 6
Click on Start Mirroring to start the mirroring from Principal database to Mirror database.
mirror18
Step 7

As you can see in the below screen shot, the status is, the databases are fully Synchronized.
mirror19
Step 8
The MirrorDB in the source server is now marked as Principal, Synchronized.
mirror20

Step 9
The MirrorDB in the destination server is now marked as Mirror, Synchronized (Restoring)
mirror21

Step 10

You can do manual failover as shown below, by selecting Failover option.
mirror22
mirror23b
Step 11

The Principal database is now changed to Mirror & the Mirror is changed to Principal as shown in the below screen shots.
mirror23
mirror24
Mirroring is a simple process & if failed we can easily reset it up, by restoring the latest backup of the source in the destination & reconfigure Mirroring.