Sunday, January 23, 2011

System.Data.SqlClient.SqlError -When Restoring a Database to SQL Server 2008

Today my friend tried to restore a database backup to SQL Server 2008 and he got the following error


Msg 3176, Level 16, State 1, Line 1 File 'D:\SQL Server 2008 DBs\test01.mdf' is claimed by 'SCTA_ORG_SECOND'(3) and 'SCTA_ORGANIZATION'(1). The WITH MOVE clause can be used to relocate one or more files.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally

let's resolve this error then we will explain the reason of this error so at the same screen used for restoring database of Microsoft SQL Server Management Studio 




select Script Action to New Query Window as the above image so you will get the following T-SQL and here we will know the reason


RESTORE DATABASE [test01] FROM  DISK = N'D:\SCTA_Org2.bak' WITH  FILE = 1,
    MOVE N'SCTA_ORGANIZATION' TO N'D:\SQL Server 2008 DBs\test01.mdf',
    MOVE N'SCTA_ORG_SECOND' TO N'D:\SQL Server 2008 DBs\test01.MDF',
    MOVE N'SCTA_ORGANIZATION_log' TO N'D:\SQL Server 2008 DBs\test01_1.ldf',
    NOUNLOAD,  STATS = 10
GO

so you will notice there are two files of mdf with the same name so just change the name of second one to test02 or to test01.ndf ( different extension) then run the command and it's successfully restored.

so the logical answer for this error first test01.mdf is a primary data file and the second is the secondary data file but the extension and name are same so that way you have to change the name or extension of second file with any other name or extension.

Note: the extension is anything ( it can be .fad or .ndf but .ndf is best practice to determine what this file for for example .ldf for log file , .ndf  for secondary data files ..).

Finally : I think the original database backup come from SQL Server 2000 and maybe this behavior allowed in SQL Server 2000 or the name is a case sensitive ( test01.mdf not like test01.MDF).

Thursday, January 13, 2011

SharePoint Server 2010 Farm Service Account - Logon as a service - SharePoint Services Timer V4

One of the requirements of SharePoint Server 2010 to build a Farm is to create a service account "Farm Service Account".


So I will describe it as person to make sure your environment run smoothly.
  1. He is as Normal user (domain user not domain admin user)
  2. This user Belong to the following SQL Roles
    1. Public
    2. Securityadmin
    3. Dbcreator
  3. Belong to Local administrators group of SharePoint servers
  4. Belong to the following local security groups:
    1.  IIS_IUSRS
    2. Performance Log Users
    3. Performance Monitor Users
    4. WSS_ADMIN_WPG
    5. WSS_RESTRICTED_WPG
    6. WSS_WPG
Note: this person will add to these groups during SharePoint Configuration Wizard but also make sure he is included in these groups.


5. Belong to the following Local Security Policy >> User Rights Assignments:
  1. Adjust memory quotas for a process
  2. b. Logon as a service (very important)
  3. c. Replace a process level token
6. This user will run the following windows services:
  1. SharePoint Services Timer V4 (very important)
  2. SharePoint Services User Code Host V4
7. This user will be used to run the application pool for Central Administration and Security Token Service.


Now couple of times I have faced this problem which is:


For example you have in your environment 2 front-end servers and when I create web application from central administration from Server A, the problem that the web application will not automatically provisioning or replicated to server B. I mean In Server B ,for example if you go to IIS you will not find the Application pool and if you go to C:\inetpub\wwwroot\wss\VirtualDirectories folder you will not find Application folder so any action occurred in Server A not copied or mirrored to Server B.


So the problem is from SharePoint Services Timer V4 which it's job to provision any modifications or updates happen in Server A to other servers because as Microsoft said "Microsoft SharePoint Server 2010 uses the Windows SharePoint Services Timer V4 (SPTimerV4) service to run most system tasks" so I found this service stopped. Why? So I try to start it again then I got this error


By the way no one reset the password of the Farm service account but I think because this service account not added to Logon as a service local policy.
So I have to go to properties of SharePoint Services Timer V4 >> Log On tab and update the password with the Old password then run the service and the problem of provision gone.


Finally make sure this user added to Logon as a service and SharePoint Services Timer V4 is running.

Wednesday, January 12, 2011

Hot Fixing ,Disconnecting and Rebuilding Sharepoint Server 2010 Farm

I have four SharePoint servers 2010 connected to SQL Server 2008 R2 Clustered in one Farm and these servers are two for Crawling and Indexing Servers and two for front-end servers so the story start from here.
I have installed this hotfix in all four servers:
http://support.microsoft.com/kb/2459257/en-us
"Description of the SharePoint Server 2010 Cumulative Update Server Hotfix Package (MOSS server-package): December 31, 2010"

so after that I restarted all servers then I run Configuration Wizard to upgrade or apply these updates.
First server in the farm run smoothly without any problem and it has updated successfully so when i tried to run the Configuration Wizard for the second server i got a message that tell me i have to install the above hotfix in current server even i have installed on it.
So after long time search and tries i have decided to remove all servers from the configuration database farm and create new Farm so first thing i did
  • remove all servers from Central Administration  >> Servers in Farm and then remove server
  • also run this power shell command in each server  PSConfig -cmd configdb -disconnect
Now the current status all server updated by the installed hotfix so i run configuration wizard in the first server and i create new farm and database.
When i tried to connect or join the other server to the new farm by running the Configuration Wizard , still the Wizard Connect to Old Configuration Database or Update mode so the configuration will failed because i have deleted the old Configuration Database even if you try through powershell by using this command PSConfig -cmd configdb -connect
so again i get help from google for searching in the internet and i read this article
http://www.sharepointblues.com/2010/05/31/disconnecting-a-sharepoint-server-from-a-farm-when-the-config-database-is-missing/
"Disconnecting a SharePoint Server from a Farm When the Config Database Is Missing"
so i come across the idea to remove the following from the regedit
ConfigDb and FarmAdmin forlder
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0\Secure


and i did it ( I know it's risk).
Then I run the configuration Wizard again to join the remaining servers and all joined and connected smoothly.

so maybe all this would not have happend if I had disconnected all servers from the farm then install the hotfix and then rejoin the servers to the farm to be all server in the same build version.

Tuesday, January 11, 2011

How to Change Diagnostic Log path in SharePoint 2010 by using PowerShell

Best Practice to change the path of Diagnostic Log to avoid disk run out of space C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\LOGS in SharePoint 2010 and this can be done by PowerShell so go to
Start >> All Programs >> Microsoft SharePoint 2010 Products >> SharePoint 2010 Management Shell

Create folder for example in D:\SharePointLog
then run this command

Set-SPDiagnosticConfig -LogLocation D:\SharePointLog\

to check if your changes applied just run this command

Get-SPDiagnosticConfig

and see the Log location path

Done

Sunday, January 9, 2011

Problem when trying to Create Search Service Application in SharePoint 2010

When i tried to create search service application in sharePoint 2010 and when i press ok after i filled the properties the process take long long time and then failed to create this service.
So my friend (currently my manager) Mr. Ismail (http://sharepoint4arab.blogspot.com) redirect me to this post on msdn
http://social.msdn.microsoft.com/Forums/en/sharepoint2010general/thread/ec0239c1-4451-46dc-ac3a-baffa006c024

so the following solved my problem:

got to regedit in sharePoint servers (Search Server) then go to this path
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0\WSS\Services\

and remove the following :


and go to this path also and remove the following:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0\WSS\ServiceProxies\


 then restart the server .

Note: maybe the name of regitery key are not same as the above image because these name created by a person who filled the properties of Search Service Application or Configuration Wizard.

Done.

Sunday, January 2, 2011

UmAlQura Custom Functoid by using Biztalk Server 2010 and Visual Studio 2010

In this article I will create UmAlQura Custom Functoid same as Date functoid which already exists in the Mapping tools.
My environment includes the following tools:
Windows 7 64 bit
Visual Studio 2010
SQL Server 2008 R2
BizTalk Server 2010
So let's start by the following steps:



First Step:
  • Create Class Library called  "UmAlQura_CF" with class named " UmAlQuraConverter.cs"
  • Add a strong –named key "key.snk"
  • Add Resource file called "UmAlQura_FC_Resource.resx" which include these properteies:
    •  Name (string)
    • Description(stirng)
    • Tooltip(string)
    • UmAlQura(Image)
  • Add this Assembly as Reference
    •  Microsoft.BizTalk.BaseFunctoids.dll" from this path C:\Program Files (x86)\Microsoft BizTalk Server 2010\Developer Tools 


So the Project structured as following:


Second Step:

Write this code to UmAlQuraConverter.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.BizTalk.BaseFunctoids;
using System.Reflection;
using System.Globalization;

namespace UmAlQura_CF
{
    /// <summary>
    /// Inherit from BaseFunctoid Abstract class
    /// </summary>
    public class UmAlQuraConverter : BaseFunctoid
    {
        public UmAlQuraConverter()
        {
            //ID of the functoid
            this.ID = 20000;

            //Resource file for the functoid
            SetupResourceAssembly("UmAlQura_CF.UmAlQura_FC_Resource", Assembly.GetExecutingAssembly());

            //Set Resource's Properties of the functoid
            //Name of functoid
            SetName("Name");
            //Tooltip of functoid
            SetTooltip("Tooltip");
            //Description of functoid
            SetDescription("Description");
            //Image of functoid
            SetBitmap("UmAlQura");

            //Set Max Params
            this.SetMaxParams(1);

            //Set the name of function to call when the functoid used. 
            SetExternalFunctionName(GetType().Assembly.FullName, "UmAlQura_CF.UmAlQuraConverter", "UmAlQuraConverterFunction");

            //Determine in which Category the functoid will appear
            this.Category = FunctoidCategory.DateTime;

            //Determine the type of node to which the output and input can be connected
            this.OutputConnectionType = ConnectionType.AllExceptRecord;
            AddInputConnectionType(ConnectionType.All);
        }

//Function of convert the current date to UmAlQura Date
        public string UmAlQuraConverterFunction(string dateFormat)
        {
            DateTime date = DateTime.Now;
            UmAlQuraCalendar umAlQuraCal = new UmAlQuraCalendar();
            CultureInfo umAlQuraCulture = new CultureInfo("ar-SA");
            umAlQuraCulture.DateTimeFormat.Calendar = umAlQuraCal;

            //return the current UmAlQura date wiht User inserted format
            return date.ToString(dateFormat, umAlQuraCulture);
        }
    }
}


Then build the project.

Third Step:
  • Add UmAlQura_CF.dll to GAC 
  • Copy UmAlQura_CF.dll to this path C:\Program Files (x86)\Microsoft BizTalk Server 2010\Developer Tools\Mapper Extensions


Forth Step:
  • Create new BizTalk Server Project from Visual studio 2010
  • Create new Schema called " TestSchema.xsd " with Date element
  • Create new Map called " TestMap.btm" and then add " TestSchema.xsd" as source and destination file for purpose of testing
  • Then open the map file and go to Toolbox and Right click and Choose items…
  • Go to BizTalk Mapper Functoids and browse to this path C:\Program Files (x86)\Microsoft BizTalk Server 2010\Developer Tools\Mapper Extensions and select the UmAlQura_CF.dll 
  • Add UmAlQura Converter control to the grid preview and set the params



Right click on the map file and then test it.
done