Thursday, August 30, 2012

database is in transition. try the statement later

 This message will get when the data base is set to offline.if we set the this property to particular database ,we can not do any transaction queries on it.
 
so the solution for this one  is to restart  the SQL server or to wait till then up to the transition process completed.The transition process time takes process.,so if you want to do any queries on it immediately ,SQL server restart is better solution as my point of view.


SQL server 2005==>goto SQL server configuration surface area==>restart the server
SQL server2008  ==>go to configuration  tools==>select SQL server==>restart

Saturday, August 25, 2012

How to create Profile programmatically in sharepoint 2010

In this post i will given a code to create profile in share point 2010 .Here i have used Userprofilemanager class to do this.Then using this i will check the the whether the user name is exist or not.If it is not exit ,it will create as user profile
using (SPSite sc = new SPSite(SPContext.Current.Site.Url))
{
SPServiceContext c = SPServiceContext.GetContext(sc);
UserProfileManager upm = new UserProfileManager(c);
SPUser su = sc.RootWeb.CurrentUser;
if (!upm.UserExists(su.LoginName))
{
upm.CreateUserProfile(su.LoginName);
}
}

Wednesday, August 22, 2012

Difference between private assembly and shared assembly

Title:What is the difference between private and shared assembly

Description:This is question we are getting whenever attended to interview .Below are some of the differences
1.In private assembly all the referred DLL's will be copied into global project debug folder but in shared assembly will not.
2.Private assemblies are faster in accessing,when compare with shared assemblies
3.Memory wise shared assembly are recommended.
4.The private assembly is used when only one project need to be developed for a client but shared assembly is used when more then one project Need to be developed

Monday, August 20, 2012

Java script validation on Server side in asp.net

Title:Java script validation in asp.net

Description :
As per previous articles,we discussed on java script validation on client side in asp.net .Now i would like give an example on validation which can be done on server side.In the below example i have used a web server control (Text box size) which should contain 30 characters with specified text format
Example:

if (TxtFormate.Text == "")
{
ClientScript.RegisterStartupScript(this.GetType(), "key", "<script>alert('Enter Format');</script>");
TxtFormate.Focus();
return;
}
if (int.Parse(TxtFormate.Text.Length.ToString()) > 30)
{
ClientScript.RegisterStartupScript(this.GetType(), "key", "<script>alert('Allows only 0 to 30 Characters');</script>");
TxtFormate.Focus();
return;
}

Sunday, August 19, 2012

Custom error settings in application in asp.net

Microsoft is providing web pages towards errors.This web pages are called"built in error pages".It will provide a lot of technical information .The solution for this is Custom error page which means the error page is provided by developer .The main purpose of custom error page in providing user friendly message.
The custom errors can be handled in two ways
1.Page level:-
This requires settings with Page Directive
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" errorpage="custom error page" %>
In this when the error occurs format towards client request processing with the web page.The client will be redirected to custom error page
2.Application Level(Web site Level):-
This requires settings under web.config
<customErrors mode="On/Off/Remote only" default Redirect="Generic error page">
<errorStatus code="error number" redirect="custom error page"/>
</customErrors">
Modes:-
On-->Custom errors will be enable for local host client and remote client
Off-->Custom errors will be disabled
Remote Only-->Errors will be enabled only for remote clients.This option will useful for live sites only

Saturday, August 18, 2012

time based cache expiration in asp.net

The life of cache variable is based on perticular rie period is called "Time based Expiry".This can classified in to 2 types
1.Absolute time expiry
2.Sliding time Expiry
The absolute time expiry will consider life time from  storage and the STE expiry will consider life time from last access time
Cache.Insert("variable",value,null,absolute time,sliding time)
Cache.Insert("n",100,null,DateTime.Now.Addminutes(5),Cache.Nosliding Expiration)
Cache.Insert("n",100,null,Cache.NoAbsolute Expiration,TimeSpan from minutes(5))

Friday, August 17, 2012

SQL cache dependency in Asp.net

The life of cache variable is based on DB[sql server] table manipulation is called SCD.Mainly the SQL cache dependence requires three steps.Those are
* configuring sql server
*configuring web site
*placing variable into cache with SQL cache expiry
Now i will show how to configuring SQL server to monitor particular table .Net is providing Asp.net -reg sql.exe utility.Open VS command prompt and type the below syntax
> aspnet - reg SQL -U "sa" -P "" -d "inventory -ed
Enable data base for sql cache dependency [it will create notification table with in Database
>asp.net -reg SQL -U "sa" -p "" -d "inventory" "-t" product" -et
Enabling table for sql cache dependency[It is asking Sql server to monitor products table for manipulation,sql server will perform manipulations to asp.net by placing info into notification table] Note:If Sql server is running in Remote System,provide server name to aspnet -regSQL.exer utility assigning -s option
aspnet -regsql -U "sa" -P "" -s "xxxx"
If sql server supports windows based authentication provide -E option
aspnet -regsql -E  -d "."
Listing tables applied with sql cache dependency
aspnet -regsql SQL -U "sa" -P "" -d "inventory" -lt

Thursday, August 16, 2012

Working process of XML web service

The below steps will give an idea of XML web service working process
1.Before consuming any web service we have to first prepare a component called Proxy(simple program/broker/mediator/interceptor)
2.client makes a request to proxy
3.proxy takes this stack request and converts into remote request.proxy will convert the request into SOAP format
4.Service takes the SOAP request and converts it into local request and finally processes it in its own environment.
5.The processed result is again serialized into XML format
6.Client proxy receives this SOAP result and provides it to client.Client can format it and produce results to their class

Wednesday, August 15, 2012

Scope of variables in javascript

In this post i will explain  how to declare and access of javascript variables.If a variable is declared inside of a function with "var" then it is local variable.
var a;-->//global
function f1()
{
//logic
}
If a variable is declared outside of a function with "var" then it is global variable.If a variable is declared implicitly any where in the code then it is global unlike other languages.
function f2()
{
var a; -->//local variable .It can access only this function
c=10;-->implicitly created.That's why global
}
We can redefine a global variable locally by declaring global variable again inside a function .Inside a function any reference will redirect to local variable only,we can use this keyword to refer global variable like this a=10;||refer to global a
function f3()
{
var b;//redefined
}

Tuesday, August 14, 2012

How to Get and check the application key values in web.config of Sharepoint site

In asp.net it is easy to access key values from web.config file using configuration assembly.Here in this post I will given an example to check whether the key value is exists or not for SharePoint site.The SharePoint provides  a class "webconfigurationManager" to access the key values from web.config file.Using the below bool method I will check the key value
 public static bool checkkeyvalues()
 {
using (SPSite sw = new SPSite(URL))
 {
 System.Configuration.Configuration cfig = WebConfigurationManager.OpenWebConfiguration("/", Sw.WebApplication.Name);
  AppSettingsSection aps = cfig.AppSettings;
return aps.ElementInformation.IsPresent;
 }
}

Monday, August 13, 2012

How to insert the data into database using string builder in asp.net

It may be given a little bit confusion to us when we go through this one.Because we would know how to insert the data into data base using sql command and one more way is to assign the sql query to string then execute the string using command.Here i would like to give an example for how to use the string builder to do for database insertion process.
 SqlConnection cn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["con"].ConnectionString);
 SqlCommand cmd;
 System.Text.StringBuilder sql = new System.Text.StringBuilder("insert into Test_Db(Name,ACompany,Email,Phone,ADD,Country)values('");
    
 sql.Append(name + "','");
 sql.Append(company + "','");
 sql.Append(Email + "','"); 
 sql.Append(phone + "','");
 sql.Append(add + "','");
 sql.Append(Country + "')");   
 cn.Open();
 cmd = new SqlCommand(sql.ToString(),cn);
 cmd.ExecuteNonQuery();

Sunday, August 12, 2012

View with check option in sql server

When a view was created without"with check option" then it will not check the condition specified in the select statement of the  view during insert,update,delete when you want to check the condition specified in  select statement of the view during insert,update&delete you must create the view with check option
Alter view
To alters a view use the alter view command that has the same syntax as create view command
Alter View<View Name>[(col1,.)][with Encryption] as <select statement>[with check option]

Wednesday, August 8, 2012

exists and not exists in sql server

The predicate EXISTS will return true when the sub query return at least one row and otherwise is returns false
NOT EXISTS will return true when the sub query return no  rows and otherwise is returns false
The below example display the details of emp to when at least one employee is reporting

select *from emp M where EXISTS(select *from emp E where E.no=M.empno)

Display the details of all departments in which there are no emps

select *from dept where not exists(select *from emp e where e.deptno=d.deptno)

Get the data of updated items fom document library in sharepoint

In this post i will given a query to get the last updated items in Document library in share point 2010.We can do this task in two ways.One is using ViewXML property and other one is using  query property.The main difference between query and ViewXML is "The view XML contains view fields,Query etc but the query does not".Here i used ViewXml property  to define the query.

SPQuery resque = new SPQuery();
resque.ViewXml = "<View><Query><OrderBy><FieldRef Name='Modified'/></OrderBy></Query><RowLimit>50</RowLimit></View>";

Monday, August 6, 2012

how to open modal popup for email in jquery

We have an option to get the Dialog box in juqery.But In this post i will given an example for how to open a model popup with custom height , width and also email data on click event .I have given focus to user name when popup in opened.
 jQuery('.email_icon').click(function () {
        openModalpopupEmail();
    });
    var openModalpopupEmail = function () {
        $.get("newemail.html", function (maildata) {
            modalWindow.windowId = "TestModal";
            modalWindow.width = 452;
            modalWindow.height = 450;
            var strres = "<div class='FBox'>";
            strres += maildata; strres += "</div>";
            modalWindow.content = strres;
            modalWindow.open();
            $("#s_name").focus(); 
        });
    };

Sunday, August 5, 2012

How to Configuring Smtp Mail Settings in theWeb.Config or App.Config

Most of the common configuration settings can be set using we3bsite administration tool.we can invoke using
website-->Asp.net configuration
The tool is mandatory for some configuration tasks for remaining we can set them manually ass well as with tool.SMTP settings can also be given using configuration tool
Mail settings:
<configuration>
<systerm.net>
<mailsettings>
<smtp from="info@site.com">
<Network host="smtp.gmail.com" password="sec" port="587" user name="sc"/>
</smtp>
</mailsettings>
</system.net>
</configuration>

All above mail settings need not be written again in programs.The above settings starting from app settings still mail settings are part of application related configuration settings.We can even specify security related information with in the configuration file.Which is also called asp.net application security configuration

Saturday, August 4, 2012

How to add column/Field to default view using powershell

In this post i will given different ways to add field to view using power shell in share point 2010 site.The first one is the basic process to add the field using power shell.In the second and final process we are used GetViewFromUrl method and splist object to add the field to view in SharePoint site .
$view=$list.views["GetAllItems"]
$view.viewfields.add($list.fields["customer"])
$view.update()
using GetViewFromUrl
$spsWeb = Get-SPWeb -Identity "http://orderssite"
$spsView = $spsWeb.GetViewFromUrl("/Lists/OrderList/GetAllItems.aspx")
$spItemField = $spList.Fields["customer"]
$spsView.ViewFields.Add($spItemField)
$spsView.Update()
Using SPList object
$spsList = Get-SPList -Url "http://orderssite/Lists/OrderList"
$spsView = $spsList.Views["GetAllItems"]
$spItemsField = $spsList.Fields["customer"]
$spsView.ViewFields.Add($spItemsField)
$spsView.Update()

Wednesday, August 1, 2012

How to open all anchors in new window/tab using javascript

In this post i will given a script to open all anchors in new tab when we click on anchors links.I have tried so many ways to do this task .Finally the below script will given the result as i need.In this script i get the anchors tags first then assign the target property to blank.
function OpenLinksInNTab()
{
  if (!document.getElementsByTagName)
  return;
  var getAllanchors = document.getElementsByTagName("a");
  for (var j=0; j<getAllanchors.length; j++)
  {
      var anchoritem = anchors[j];
      if(anchoritem.getAttribute("href"))
   anchoritem.target = "_blank";
  }
}
window.onload = OpenLinksInNTab;

Bel