Wednesday, February 13, 2019

(Or)

HOW TO BRING BACK THE SUSPECTED DATABASE TO THE NORMAL MODE

When you login into the SQL management then you might have seen that one/some of your database has been Suspected State, because of the applications which run using this DB’s will not function and it will generate error while accessing those applications.

Cause:
Improper shutdown of the SQL server (in my case)

Probable causes that bring Databases into Suspect Mode are:
Ø  Hardware failure
Ø  Improper shutdown of the SQL server
Ø  Corruption of the database files and log files
Ø  Not enough disk space when writing data
Ø  Unavailable database files
Ø  Database resource used by operating system
Ø  SQL Server incorrectly asserts free data page space when a row is inserted

Resolution:

To fix this issue follow below steps:

Change the status of your database
Right click on the database and select New Query and then Execute the following command.
EXEC sp_resetstatus DBNAME;
Ex: -   EXEC sp_resetstatus ‘SharePoint_Config’;

Set the database in “Emergency” mode
ALTER DATABASE DBNAME SET EMERGENCY
Ex: -  ALTER DATABASE  SharePoint_Config SET EMERGENCY

Check the database for any inconsistency
DBCC checkdb(‘DBNAME’)
Ex: -   DBCC checkdb(‘SharePoint_Config’)

If you get any error after executing DBCC CHECKDB then immediately bring the database in SINGLE USER MODE by running following query. If no error found then you need not execute the following query.
ALTER DATABASE DBNAME SET SINGLE_USER WITH ROLLBACK IMMEDIATE
Ex: -   ALTER DATABASE SharePoint_Config SET SINGLE_USER WITH ROLLBACK IMMEDIATE

Run the following query as next step. Remember while using the below query, that uses REPAIR_ALLOW_DATA_LOSS, is a one way operation that is once the database is repaired all the actions performed by these queries can’t be undone. There is no way to go back to the previous state of the database. So as a precautionary step you should take backup of your database.

DBCC CHECKDB (' DBNAME ', REPAIR_ALLOW_DATA_LOSS);
Example: DBCC Checkdb (‘SharePoint_Config’, REPAIR_ALLOW_DATA_LOSS)

 Finally, bring the database in MULTI USER mode

ALTER DATABASE DBNAME SET MULTI_USER;

ALTER DATABASE [SharePoint_Config] SET MULTI_USER

Reference:

Source: https://msspadmin.blogspot.com/2014/07/how-to-recover-sql-database-from.html?showComment=1550127339127 

Sunday, June 10, 2018

Using Nhibernate in SharePoint 2010

Running Nhibernate on Sharepoint is not an easy task it might take 1 or 2 days to do it, in this tutorial I will try this task easy by providing a step by step guide starting from how to download NHibernate to how to configure it on sharepoint

You can download the latest Nhibernate version from: http://sourceforge.net/projects/nhibernate/
In my tutorial I am assuming that you know what’s NHibernate and how to use it, if it’s the first time to hear about NHibernate please read the following tutorial first: http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/01/your-first-nhibernate-based-application.aspx

HBM & CS Classes Generators

There are many ways to generate HBM and CS classes
1) MYGeneration Templates: I do not recommend these templates because most of them are not updated to NHibernate newer versions and it’s not easy to change in its templates
Download link: http://www.mygenerationsoftware.com 
2) Smart Code Studio: it’s a better way to generate the hbm files and CS classes, I’ve modified in its template to be more standard and simple, you can download my template from this link.
(if you are not using Smart Code Studio you can watch a video on how to use it from this link http://www.kontac.net/site/SmartCode/tabid/55/Default.aspx )
Download link: http://www.kontac.net/site/SmartCode/Download/tabid/64/Default.aspx

Using NHibernate in your sharepoint project:

Create a new class library project in your solution called ABC.Domain and generate the hbm files and cs classes then place into it.

Make sure that all hbm classes are compiled as Embedded resources


Create another class library project called ABC.BL to use the Domain project and to be used by the share point project, don’t forget to add both classes to GAC using gacutil command.

Extract the Nhibernate folder and make sure to add reference to the following DLLs + Adding reference to your Domain project
Remotion.Data.Linq.dll
NHibernate.dll
Nhibernate.ByteCode.Linfu.dll
NHibernate.ByteCode.Castle.dll
log4net.dll
LinFu.DynamicProxy.dll
Iesi.Collections.dll
Castle.DynamicProxy2.dll
Castle.Core.dll
Antlr3.Runtime.dll



After adding the references to your project make sure to install them to GAC by executing the following commands on Visual Studio Command Prompt
gacutil -i "\Remotion.Data.Linq.dll"
gacutil -i "\NHibernate.dll"
gacutil -i "\Nhibernate.ByteCode.Linfu.dll"
gacutil -i "\NHibernate.ByteCode.Castle.dll"
gacutil -i "\log4net.dll"
gacutil -i "\LinFu.DynamicProxy.dll"
gacutil -i "\Iesi.Collections.dll"
gacutil -i "\Castle.DynamicProxy2.dll"
gacutil -i "\Castle.Core.dll"
gacutil -i "\Antlr3.Runtime.dll"
gacutil -i "\ABC.Domain\Bin\Debug\ABC.Domain.dll"

Configure your Web.config & hibernate.cfg.xml

Prepare you hibernate.cfg.xml and place it inot your website bin folder (eg. C:\inetpub\wwwroot\wss\VirtualDirectories\80\bin)

Now All references and configurations are ready, but if you tried to deploy your solution you will get a run time error “Could not load file or assembly 'xyz' or one of its dependencies”, Now you will just need to add qualifyAssembly tags to your web.config (eg C:\inetpub\wwwroot\wss\VirtualDirectories\80\ ) to allow Nhibernate to load assemblies form GAC and not to expect it in the bin folder.

To use Nhibernate inside your sharepoint project you can refer to this tutorial http://www.codegod.de/WebAppCodeGod/nhibernate-tutorial-1---and-aspnet-AID25.aspx 


source :  http://hazemtorab.blogspot.com/2010/08/using-nhibernate-in-sharepoint-2010.html 

Thursday, January 4, 2018

Query Strings in ASP.Net

QueryString is a collection of characters input to a computer or web browser. A Query String is helpful when we want to transfer a value from one page to another. When we need to pass content between the HTML pages or aspx Web Forms in the context of ASP.NET, a Query String is very easy to use and the Query String follows a separating character, usually a Question Mark (?). It is basically used for identifying data appearing after this separating symbol. A Query String Collection is used to retrieve the variable values in the HTTP query string. If we want to transfer a large amount of data then we can't use the Request.QueryString. Query Strings are also generated by form submission or can be used by a user typing a query into the address bar of the browsers. Query Strings are contained in request headers. A Query String collection is a parsed version of the QUERY_STRING variable in the Server Variables collection. It enable us to retrieve the QUERY_STRING variable by name. When we use parameters with Request.QueryString, the server parses the parameters sent to the request and returns the effective or specified data.
Syntax of Query String
Request.QueryString(variable)[(index).count].
Step 1
Start Visual Studio.
 
Figure 1: Start Visual Studio 
Step 2
Now for creating a website, click on the file, go to new and click on the website.
 
Figure 2: Create Website
Step 3
Now we add the two web forms to the website.
Add Webform 
Figure 3: Add Web form 
Step 4
 
We design the web form as in the following:
 
Figure 4: Design form
Step 5
After designing the web form, we need to write the following code in the button click.

  1. protected void Button1_Click(object sender, EventArgs e)   
  2. {  
  3.     Response.Redirect("default2.aspx ?firstname=" + TextBox1.Text + "&lastname=" + TextBox2.Text);  
  4. }  
 Step 6
In the second web form we take the one lable for displaying the values of the first page. For receiving the value from the first page we write the following code on the page_load of the second page.
  1. protected void Page_Load(object sender, EventArgs e)   
  2. {  
  3.     string firstname = Request.QueryString["firstname"];  
  4.     string lastname = Request.QueryString["lastname"];  
  5.     Label1.Text = "welcome" + firstname + " " + lastname;  
  6. }  
 Step 7
Now we need to execute the website by using the F5 key. After execution we give the input in the textboxes like this:
Execute
Figure 5: Execute Web Form
Figure 6: Input in the Textboxes
Step 8
After giving the values, we click on the Submit button then the following window will appear.
Figure 7: Final Window
Summary
In this article, I explained how to use Query Strings in ASP.NET, now you can easily do these operations in your projects for transferring a value of one page to another page.
I hope this article will be helpful for the beginners if they want to transfer data from one page to the another.
------------------------------------------------------------------------------------------------------------------------------------
source: http://www.c-sharpcorner.com/UploadFile/ca2535/query-string-in-Asp-Net/ 

Thursday, December 28, 2017

Close SharePoint Pop-up window

 Context.Response.Write("<script type='text/javascript'>window.frameElement.commitPopup()</script>");
            Context.Response.Flush();
            Context.Response.End();

Wednesday, November 1, 2017

Installing and configuring Workflow for SharePoint Server 2013

When you open SharePoint Designer 2013 connected to a site to build a workflow, you will notice a new option called platform type. If it’s only “SharePoint 2010 Workflow” that you see, you need to install and configure “workflow manager”.

As MSDN recommends, you need to consider the following two key factors before configuring Workflow Manager to work with SharePoint Server 2013.
  • Is Workflow Manager installed on a server that is part of the SharePoint farm?
  • Will communication between Workflow Manager and SharePoint Server 2013 use HTTP or HTTPS?
These factors translate into four scenarios. Each scenario configures a SharePoint Server 2013 farm to communicate and function with the Workflow Manager farm. Follow the scenario that matches your circumstance.
  1. Workflow Manager is installed on a server that is part of the SharePoint 2013 farm. Communication takes place by using HTTP.
  2. Workflow Manager is installed on a server that is part of the SharePoint 2013 farm. Communication takes place by using HTTPS.
  3. Workflow Manager is installed on a server that is NOT part of the SharePoint 2013 farm. Communication takes place by using HTTP.
  4. Workflow Manager is installed on a server that is NOT part of the SharePoint 2013 farm. Communication takes place by using HTTPS.
Mine is the 1st scenario. Workflow Manager can be downloaded from here. Workflow Manager installation uses Web Platform Installer as shown in the below screen.
image
image
Then you need to install the prerequisites.
image
image
image
Clicking continue will bring the configuration options.
image
I prefer to go with the custom setting as I can get to know what’s going on behind scene. If you select the “Configure Workflow Manager with Default Settings (Recommended)”, it will install a Workflow Manager farm. So let’s move with custom :)
In the below screen you need to specify the database server, where it will create the DBs needed for WM(Workflow Manager).
image
Make sure you remember or keep safe the Certificate Generation Key, as it’s needed when you want to add more servers to the WM farm.
image
Service account will be used to run the Application pool of the WM Website.
image
Below screen looks nice so added that too :D
image
image
image
image
Three screens below show the full configuration summary.
image
image
image
You can even see the full PowerShell script for the configuration.
image
image
image
image
Great!! You are done with the installation and the configuration of Workflow Manager. Yet one more step left for the Workflows to work in 2013 Platform. Open IIS Manager to see the WM Site and the port you configured.
image
Open SharePoint Management Shell with Admin rights and execute the below cmdlet (replacing the site and the Workflow Manager host site).
Register-SPWorkflowService –SPSite "http://www.whiteknight.com/Hr" –WorkflowHostUri "http://workflow.whiteknight.com:12291" –AllowOAuthHttp
Finally to check whether everything works fine… Open the above site (registered with workflow host uri) in SharePoint Designer 2013 and check the Platform type in workflow.
Workflow Manager 1.0
When you install Workflow Manager on a WFE it automatically installs the Workflow Manager Client on that WFE. You will still need to install the Workflow Manager Client on any additional WFE servers.
---------------------------------------------------------------------------------------------------------------------

Source: http://prabathf.blogspot.com/2013/02/installing-and-configuring-workflow-for.html 

Send Email C#

MailMessage Mail = new MailMessage("email", SPuser.User.Email);
Mail.Subject = " ";
Mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient("")
                                {
                                    DeliveryMethod = SmtpDeliveryMethod.Network,
                                    Credentials = new NetworkCredential()
                                };
                                smtp.EnableSsl = false;
                                smtp.Send(Mail);

Tuesday, October 10, 2017

Dynamically create CAML query

public string GenerateQuery(IList<CamlQueryElements> lstOfElement)
    {
        StringBuilder queryJoin = new StringBuilder();
        string query = @"<{0}><FieldRef Name='{1}' /><Value {2} Type='{3}'>{4}</Value></Eq>";
        if (lstOfElement.Count > 0)
        {
            int itemCount = 0;
            foreach (CamlQueryElements element in lstOfElement)
            {
                itemCount++;
                string date = string.Empty;
                // Display only Date
                if (String.Compare(element.FieldType, "DateTime", true) == 0)
                    date = "IncludeTimeValue='false'";
                queryJoin.AppendFormat(string.Format(query, element.ComparisonOperators,
                                element.FieldName, date, element.FieldType, element.FieldValue));

                if (itemCount >= 2)
                {
                    queryJoin.Insert(0, string.Format("<{0}>", element.LogicalJoin));
                    queryJoin.Append(string.Format("</{0}>", element.LogicalJoin));
                }
            }
            queryJoin.Insert(0, "<Where>");
            queryJoin.Append("</Where>");
        }
        return queryJoin.ToString();
    }

source: https://stackoverflow.com/questions/8267515/dynamically-create-caml-query?rq=1 

HOW TO RECOVER THE SQL DATABASE FROM SUSPECT MODE (Or) HOW TO BRING BACK THE SUSPECTED DATABASE TO THE NORMAL MODE When you logi...