Thursday, May 31, 2012

enable database Service broker in sql server 2005 -2008

Enabling Sevice broker in sql server

Step 1.  Go to Sql server management studio & open Database properties >> options>>  Broker enabled set to true


OR

STEP 2 :

Exeute query >> alter database [your database name] set enable_broker


Alter Database column change size

Query >>ALTER TABLE MyTable ALTER COLUMN NullCOl NVARCHAR(20) NOT NULL;

Monday, May 28, 2012

Calculate number of days in month in sql server



Create simple Scalar - Valued  function (UDF) with input parameter month & Year

Create FUNCTION [dbo].[Days_in_Month]
    (
    @month int,
    @year int
   
    )
RETURNS int
AS
BEGIN
   


DECLARE @Days int

 select @Days= datepart(dd,dateadd(dd,-1,dateadd(mm,1,cast(cast(@year as varchar)+'-'+cast(@month as varchar)+'-01' as datetime))))



    RETURN @Days
END

Run following script in Query Editor:
SELECT dbo.Days_in_Month(1,2012) as NumDaysInMonth

Tuesday, May 22, 2012

Asp.net Questions

1. What is ASP?
Active Server Pages (ASP), also known as Classic ASP, is a Microsoft's server-side technology, which helps in creating dynamic and user-friendly Web pages. It uses different scripting languages to create dynamic Web pages, which can be run on any type of browser. The Web pages are built by using either VBScript or JavaScript and these Web pages have access to the same services as Windows application, including ADO (ActiveX Data Objects) for database access, SMTP (Simple Mail Transfer Protocol) for e-mail, and the entire COM (Component Object Model) structure used in the Windows environment. ASP is implemented through a dynamic-link library (asp.dll) that is called by the IIS server when a Web page is requested from the server.
2. What is ASP.NET?
ASP.NET is a specification developed by Microsoft to create dynamic Web applications, Web sites, and Web services. It is a part of .NET Framework. You can create ASP.NET applications in most of the .NET compatible languages, such as Visual Basic, C#, and J#. The ASP.NET compiles the Web pages and provides much better performance than scripting languages, such as VBScript. The Web Forms support to create powerful forms-based Web pages. You can use ASP.NET Web server controls to create interactive Web applications. With the help of Web server controls, you can easily create a Web application.
3. What is the basic difference between ASP and ASP.NET?
The basic difference between ASP and ASP.NET is that ASP is interpreted; whereas, ASP.NET is compiled. This implies that since ASP uses VBScript; therefore, when an ASP page is executed, it is interpreted. On the other hand, ASP.NET uses .NET languages, such as C# and VB.NET, which are compiled to Microsoft Intermediate Language (MSIL).
4. In which event are the controls fully loaded?
Page load event guarantees that all controls are fully loaded. Controls are also accessed in Page_Init events but you will see that view state is not fully loaded during this event
5. How can we identify that the Page is Post Back?
Page object has an "IsPostBack" property, which can be checked to know that is the page posted back.
6. What is the lifespan for items stored in ViewState?
The items stored in ViewState live until the lifetime of the current page expires including the postbacks to the same page.
7.What are the advantages of the code-behind feature?


  • Makes code easy to understand and debug by separating application logic from HTML tags
  • Provides the isolation of effort between graphic designers and software engineers
  • Removes the problems of browser incompatibility by providing code files to exist on the Web server and supporting Web pages to be compiled on demand.

Wednesday, May 16, 2012

Listbox to Listbox Data transfer in Asp.net C#




List Box control is a standard control in Asp.net. It is similar to a dropdownlist.
An article to demonstrate How to Move List Box Items to another List Box in ASP.NET and C#. 



CODE

Listbox1 items adding  to listbox2

protected void btnadditemlist_Click(object sender, EventArgs e)
     {
         foreach (ListItem item in listbox1.Items)
         {
             if (item.Selected)
             {
                 if (listbox2.Items.Contains(item))
                 {
                     // Display message
                     return;
                 }




                 string _value = item.Value; //Gets the value of items in list.
                 string _text = item.Text;  // Gets the Text of items in the list. 
               

                 ListItem items = new ListItem(); //create a list item
                 items.Text = _text;               //Assign the values to list item  
                 items.Value = _value;

               
                 listbox2.Items.Add(items);
             }
         }
     }


Removing Data from Listbox 2

protected void Remove_Click(object sender, EventArgs e)
    {
        foreach (ListItem item in ListBox2.Items)
        {
            if (item.Selected)
            {


                //ListBox2.Items.Remove(item);
                selectedItems.Add(item);

            }
        }
        for (var i = 0; i < selectedItems.Count; i++)
        {
                       ListBox2.Items.Remove((ListItem)selectedItems[i]);

        }
    }

Friday, May 11, 2012

Clear Drop Down List of Recent Connection From SQL Server Management Studio


Delete mru.dat file in xp-os in Windows7 Delete  SqlStudio.bin

 Sql 2005
C:\Documents and Settings\\Application Data\Microsoft\Microsoft SQL Server\90\Tools\Shell\mru.dat
If you can not find mru.dat at above location look for mru.dat in following folder.
C:\Documents and Settings\[user]\Application Data\Microsoft\Microsoft SQL Server\90\Tools\ShellSEM\mru.dat
For SQL Server 2008:
C:\Documents and Settings\\Application Data\Microsoft\Microsoft SQL Server\100\Tools\Shell\mru.dat
If you can not find mru.dat at above location look for mru.dat in following folder.
C:\Documents and Settings\[user]\Application Data\Microsoft\Microsoft SQL Server\100\Tools\ShellSEM\mru.dat
 For SQL Server 2008 R2:
in Windows7 Delete  SqlStudio.bin  file from location
  C:\Users\[user]\AppData\Roaming\Microsoft\Microsoft SQL Server\100\Tools\Shell\

Save a PDF generated from html2pdf in C#, MVC , html2pdf , Ajax code

 To save on server or disk a PDF generated from HTML in C# code example, you can use the      html2pdf js script     html2pdf   converts any...