Wednesday, January 29, 2014

How to share folders using C# .NET

There are many cases you may have to share the data with other computer/Users. If anybody have more than one computer and want to transfer some file over it you have to share the folder so that other users will be able to access the files inside the shared folder. Read this article to learn how to share a folder over your local network using ASP.NET.

For implementing this concept I have created one webpage like below.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ShareFolder.aspx.cs" Inherits="Blog.ShareFolder" %>
 
<!DOCTYPE html>
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .auto-style1 {
            width: 100%;
        }
        .auto-style2 {
            width: 169px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <table class="auto-style1">
            <tr>
                <td class="auto-style2">
                    <asp:Label ID="Label1" runat="server" Text="Share Folder Path"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtPath" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="auto-style2">
                    <asp:Label ID="Label2" runat="server" Text="Share Folder Name"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="auto-style2">
                    <asp:Label ID="Label3" runat="server" Text="Share Folder Description"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtDesc" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="auto-style2">&nbsp;</td>
                <td>
                    <asp:Button ID="btnShare" runat="server" OnClick="btnShare_Click" Text="Share Folder" />
                </td>
            </tr>
        </table>
    <div>
    
        <asp:Label ID="lblResult" runat="server"></asp:Label>
    
    </div>
    </form>
</body>
</html>

Here I am using three TextBox.

1. txtPath        - To enter complete folder path which you want to share

2. txtName      - Folder name to be displayed for shared folder

3. txtDesc       -  Description for the shared folder

First we need  to create a directory and subdirectories in the specified path given in the first TextBox.

Directory.CreateDirectory(strSharePath);

Next step is to create a management class. For that we need to add a reference System.Management. You can refer below screen print to know how to add the reference.

reference

Then create a Shared folder with the name and description what we got through TextBox.

Here is the complete code you may use for this purpose:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Management;
 
namespace Blog
{
    public partial class ShareFolder : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
 
        }
 
        protected void btnShare_Click(object sender, EventArgs e)
        {
            string strSharePath = txtPath.Text.ToString();
            string strShareName = txtName.Text.ToString();
            string strShareDesc = txtDesc.Text.ToString();
            try
            {
                Directory.CreateDirectory(strSharePath);
                ManagementClass oManagementClass = new ManagementClass("Win32_Share");
                ManagementBaseObject inputParameters = oManagementClass.GetMethodParameters("Create");
                ManagementBaseObject outputParameters;
                inputParameters["Description"] = strShareDesc;
                inputParameters["Name"] = strShareName;
                inputParameters["Path"] = strSharePath;
                inputParameters["Type"] = 0x0;//disk drive 
                inputParameters["MaximumAllowed"] = null;
                inputParameters["Access"] = null;//Make Everyone has full control access
 
                inputParameters["Password"] = null;
 
 
                outputParameters = oManagementClass.InvokeMethod("Create", inputParameters, null);//// Invoke the method on the ManagementClass object
                if ((uint)(outputParameters.Properties["ReturnValue"].Value) != 0)
                {
 
                    throw new Exception("There is a problem while sharing the directory.");
 
                }
                else
                {
                    lblResult.Text = "Share Folder has been created with the name :" + strShareName;
                }
            
                
            }
            catch(Exception ex)
            {
                lblResult.Text = ex.Message.ToString();
            }
        }
    }
}

You have many more options for the Create method of the Win32_Share class, you can read all this option from MSDN article.

After running the code, you will be seeing the interface like below. You can also see the data which you need to enter in below screen print.

share

Once you execute the code successfully your folder will be shared like below,

share1

Thursday, January 23, 2014

Ajax Animation Extender control

Are you thinking of decorating your website with some animation? Then there is one simple and useful control in AjaxControlToolkit named Animation extender which help you to give excellent animation to your pages.

You can apply animations to target control when some events likes, OnLoad, OnClick, OnMouseOver, or OnMouseOut raised. Here I am trying to explain how this Ajax Animation Control will work.

STEP : 1 Create a new webform

Create a new webform in ASP.NET. Drag and drop ToolScriptManager, Panel and a Animation Extender control.

animationextender

STEP 2 : Create a CSS class to the panel

Here I am using a panel for animation which is the target control. First I created a style sheet for the panel.

<style>
     .animationPanel
        {
        position : absolute;
        height : 250px;
        width: 300px;
        top: 100px;
        left: 400px;
        border-width: 2px;
        border-color:red;
        border-style:solid;
        }
        </style>

STEP 3 : Write animation properties

First I set animation property for the text inside the panel and then I set the animation for panel. Here I am doing the animation sequentially. I wrote the code on click event of the panel.

So the entire .aspx page looks like below.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Ajaxanimation.aspx.cs" Inherits="Blog.Ajaxanimation" %>
 
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
 
<!DOCTYPE html>
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>AjaxAnimation</title>
    <style>
     .animationPanel
        {
        position : absolute;
        height : 250px;
        width: 300px;
        top: 100px;
        left: 400px;
        border-width: 2px;
        border-color:red;
        border-style:solid;
        }
        </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        </asp:ToolkitScriptManager>
        <br />
         <asp:Panel ID="ajaxPanel" runat="server" CssClass="animationPanel">
                    Click me!!! I will move...<br><br><br>
             <div id ="info">
             Thanks for vising asheej.blogspot.com<br>
             You are reading the article related to AJAX animation extender
                 </div>
            </asp:Panel>
 
        <asp:AnimationExtender ID="AnimationExtender1" runat="server" TargetControlID="ajaxPanel">
            <Animations>
                 <OnClick>
 
        <Sequence><%-- Sequance is used to do the animation sequantially --%> 
 
            <%-- Below code will help you to move the Panel --%> 
 
 
                      
            <Parallel AnimationTarget="info" Duration=".2">
                <Color PropertyKey="color"
                        StartValue="#0000CD" EndValue="#FF0000" />
                <Color PropertyKey="borderColor"
                        StartValue="#0000CD" EndValue="#FF0000" />
            </Parallel>
 
            <Parallel AnimationTarget="info" Duration=".2">
                <Color PropertyKey="color"
                        StartValue="#FF0000" EndValue="#666666" />
                <Color PropertyKey="borderColor"
                        StartValue="#FF0000" EndValue="#666666" />
            </Parallel>
 
                <Parallel AnimationTarget="flyout" Duration=".1" Fps="30">
                <Move Horizontal="200" Vertical="-75" />
                <Resize Height="300" Width="300" />
                <Color AnimationTarget="info" PropertyKey="backgroundColor"
                        StartValue="#ADFF2F" EndValue="#00FFFF" />
            </Parallel>
            
        </Sequence>
    </OnClick>
          
            </Animations>
        </asp:AnimationExtender>
 
    </div>
    </form>
</body>
</html>
 

STEP 4 : Build the solution and run the application

After running the code the result should be looks like this:

ajaxanimation

 

AnimationExtender Control properties:

  • TargetControlID : It is the ID of the control to which animation occurs.
  • OnLoad             : Set the animation when the page is loaded
  • OnClick             : Set the animation when the target control is clicked
  • OnMouseOver   : Set the animation when the mouse moves over the target control
  • OnMouseOut     : Set the animation when the mouse moves out the target control
  • OnHoverOver    : Set the animation when the mouse moves over the target control. But it stop the OnHoverOut  animation before it plays.
  • OnHoverOut      : Set the animation when the mouse moves out the target control. But it stop the OnHoverOver  animation before it plays.

Wednesday, January 22, 2014

Ajax rating Control

Are you planning to use Rating Control in your application from Ajax Control toolkit? This article is trying to give information on AJAX Rating Control and how to use this control. The main purpose of AJAX Rating Control is to give a chance to user for rating or reviewing content in your website.

To use Ajax Rating Control, first we have to install Ajax control toolkit. If you haven’t installed AjaxControlToolkit you may refer my article

Let me show you how I used Ajax Rating control.

Step 1 : Create .aspx page

First we need to add One Label, ToolkitScriptManager and Ajax rating Control to the webpage.

Rating1

Do you have any doubt, why I have used ToolkitScriptManager instead of ScriptManager? First I dropped ScriptManager in the webpage but while running, I got an error “0x800a138f - JavaScript runtime error: Unable to get property 'UI' of undefined or null reference” like below.

Rating2

This exception can be avoided using toolscriptManager because most of the controls from AjaxToolKit work using Ajax script. ToolkitScriptManager adds most of the updated Ajax Script.

Step 2 : Create CSS files and save images

Here I am using 3 images to show the state (Empty,Filled, Saved) of rating control. For that you need to create a folder in your project root directory and save three star images for visible star, star in waiting mode and star in filled mode.

Now the time for adding CSS class in the head section.

.filledRatingStar {
    background-image: url(Images/FilledStar.png);
}
.emptyRatingStar {
    background-image: url(Images/EmptyStar.png);
}
.savedRatingStar {
    background-image: url(Images/SavedStar.png);
}

Step 3 : Set some properties of Ajax rating control

Some properties need to set to Ajax rating Control. They are :

  • CurrentRating - Initial rating value
  • Direction        - Orientation of the stars
  • MaxRating     -  Initial rating value
  • EmptyStarCssClass - CSS class for star in empty mode
  • FilledStarCssClass   - CSS class for star in filled mode
  • StarCssClass          - CSS class for a visible class
  • WaitingStarCssClass - CSS class for the star in waiting mode

After doing all the above 3 steps,the source page should look like this:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RatingControl.aspx.cs" Inherits="Blog.RatingControl" %>
 
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
 
<!DOCTYPE html>
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style>
 
.ratingStar {
    font-size: 0pt;
    width: 15px;
    height: 50px;
    margin: 0px;
    padding: 0px;
    cursor: pointer;
    display: block;
    background-repeat: no-repeat;
}
 /*You need to make sure that Images folder is created in your Project root directory and copy the images in this folder */
.filledRatingStar {
    background-image: url(Images/FilledStar.png);
}
.emptyRatingStar {
    background-image: url(Images/EmptyStar.png);
}
.savedRatingStar {
    background-image: url(Images/SavedStar.png);
}
    </style>
 
</head>
<body style="height: 83px">
    <form id="form1" runat="server">
    <div>
           
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
 </asp:ToolkitScriptManager>
                <asp:Label ID="lblrate" runat="server" Text="Rate this blog"></asp:Label>
        
        <asp:Rating ID="Rating1" runat="server" RatingAlign="Horizontal"
            CurrentRating ="1"
            EmptyStarCssClass="emptyRatingStar" 
            FilledStarCssClass="filledRatingStar" 
            RatingDirection="LeftToRightTopToBottom" 
            StarCssClass="ratingStar" 
            WaitingStarCssClass="savedRatingStar" 
            Direction="LeftToRight">
        </asp:Rating>
    
    </div>
    </form>
</body>
</html>

Output

rating3

Hope you enjoy reading this article, if you have any comment please post below…

Tuesday, January 21, 2014

Could not load file or assembly 'AjaxMin, Version=4.97.4951.28478, Culture=neutral, PublicKeyToken=21ef50ce11b5d80f' or one of its dependencies. The system cannot find the file specified.

This is one of the common error you get when you start using AJAX first time in your project. Nothing to panic about this, you can easily resolve the error “System.IO.FileNotFoundException: Could not load file or assembly 'AjaxMin, Version=4.97.4951.28478, Culture=neutral, PublicKeyToken=21ef50ce11b5d80f' or one of its dependencies. The system cannot find the file specified.” by copying the missing dll in the correct folder.

image

If you look at the error once again you may notice that error clearly suggest it cannot find the assembly 'AjaxMin’ which means once you open your project bin folder you may not find the 'AjaxMin.dll’ file.

So to resolve this issue what you have to do is, search for 'AjaxMin.dll’ and copy this into the project bin folder.

image

After copying this 'AjaxMin.dll’ in your project bin folder try to run the application and see if it works fine.

Tuesday, December 31, 2013

What is SET NOCOUNT in SQL Server

You must have seen the statement SET NOCOUNT ON in most of the stored procedure. When I saw this message first time I was thinking why this has been used in almost all stored procedure what will happen if I set SET NOCOUNT OFF in place of ON. Here in this article I thought I will share you the advantage of using SET NOCOUNT ON in SQL Stored Procedure and how this will improve the performance of your query.

The main advantage of using SET NOCOUNT ON in your stored procedure or TSQL statement is, this statement automatically suppress the message which shows how many rows has been affected by the query. Which means, this will reduce the overhead of the server and improves the performance when you execute query in a table which has got millions of data.

What exactly is happening inside the server is when you execute a stored procedure with SET NOCOUNT ON  it prevents the sending of DONE_IN_PROC messages to the client for each statement in your stored procedure. Imagine you have a loop or several statement has to be executed!!! So using SET NOCOUNT ON will definitely boost your query performance and adding the line SET NOCOUNT ON is one of the main DBA tasks when they find that query or procedure is not performing well.

If you wanted to know the message of affected rows then you can add SET NOCOUNT OFF in your query. This will show the number of rows affected by executing the query.

Irrespective of using SET NOCOUNT ON or SET NOCOUNT ON  SQL server internally updates @@ROWCOUNT function. So querying @@ROWCOUNT function will give you the affected rows details at any time.

Now let’s see how it shows in SQL query analyzer,

Below is my stored procedure, you can notice that I have commented the line SET NOCOUNT ON. 

CREATE PROCEDURE [dbo].[sp_GetCustomerList]
AS
BEGIN
    --SET NOCOUNT ON;
    SELECT * from Customer
END
 

We will execute this procedure and see the result.

image

Now we will un comment the line SET NOCOUNT ON and see the output,

CREATE PROCEDURE [dbo].[sp_GetCustomerList]
AS
BEGIN
    SET NOCOUNT ON;
    SELECT * from Customer
END

image

Hope you are now clear about the usage of SET NOCOUNT ON.

Monday, December 30, 2013

How to use NuGet Package Manager for Visual Studio 2013

Have you ever heard about NuGet Package? Do you know how to use NuGet Package manager and how to install AJAXControlToolkit using NuGet Package Manager. Here is the answer for all your doubts related to NuGet Package manager for Visual Studio.

Pre-Requisite: System with Visual Studio 2013 and Good Internet Connection

First we will download NuGet Package manager for Visual Studio 2013. You may use the this link :NuGet Package Manager for Visual Studio 2013 for downloading the package.

Once you install the package open Visual Studio 2013 and open the Package Manager Console.

Refer below image to know how to open NuGet Package Manager Console.

image

Once you click on the Package Manager Console you will find a consol window link below

image

Here is the place you execute the command install AjaxControlToolkit. As I mentioned earlier you should have good internet connection to download the AjaxControlToolKit otherwise it will throw error.

The command you execute to install AjaxControlToolkit is :PM> Install-Package AjaxControlToolkit

image

Once you execute the command Install-Package AjaxControlToolkit it may take few seconds and you will below updates,

image

Finally when the installation completes you will find below updates,

image

There are many inbuilt commands available in NuGet you can find the help by running the command get-help NuGet and explore all possible options.

Tuesday, December 17, 2013

How to edit .rdlc file to add new column

I have a requirement to add new column in existing report. Unfortunately rdlc file was given by a third party vendor and we don’t have the complete project and dataset to edit the file.

As you are aware .rdlc is just an XML file, once you open that in notepad or any editor you can see what and all contents are visible in reports. But if you start editing the .rdlc file manually it will be a never ending process.

Here we are going to edit .rdlc file by using Visual Studio. Of course you require Visual Studio Business Intelligence to edit .rdlc file, also I am expecting you to have an access to the database to add new field in your stored procedure or SQL query which is executed from .rdlc to populate the data in reports.

Now we will go to step by step procedure.

1. Convert .rdlc to .rdl first—> This is a very simple technique. You just need to change the extension from .rdlc to .rdl. This will automatically convert the file.

2. Open Visual Studio business intelligence and select new—> Project—> Report project.

3. Right Click solution and select Add—>Existing Items—> Locate your renamed .rdl file.

 1. Add RDL file

2. Add Existing RDL file

4. Double Click .rdl file to open it in design mode.

5. Select the last field or the field near to the new one you are going to add. In this example I am adding the new column as the last one.

6. Right Click on the selected field and select Insert Column. You can opt either left or right depends on your choice.

3. Insert New column in RDL file

7. Provide required name for the new fields. Here I am giving the name as Test.

4. New column in RDL file

8. Now we will add new field in the DataSet. Click on View menu and select report Data to show the dataset.

5. View DataSet and DataSource in SSRS

9. Right Click Dataset and select DataSet Properties.

6. Add new column in DataSet

6. Click on Add button to add new field in the DataSet.

7. Add new column in DataSet

8. Add new column in DataSet

7. And the last steps is to modify your Stored procedure/SQL query to add the new field you added in the reports.

8. Now it’s the time to convert .rdl to .rdlc. and it is exactly same as the firs step, just change the extension from .rdl to .rdlc.

Just copy the .rdlc file in your project folder where it has been placed earlier and access it from your application…That’s it!!!

If you have any doubt or confusion in above steps you can always contact me using my mail ID or write comment below.

Tuesday, November 5, 2013

Rename Stand-Alone Instance of SQL Server 2012 Database

Are you looking for an option to rename the SQL 2012 database? If you have an existing stand-alone instance of an SQL 2012 database you wanted to rename the database then this cannot be down from object explorer. When you right click on your database you will be surprised that Rename option will be disabled. Ok, don’t get panic we an do this renaming by running simple query.

Let’s how does it looks if you right click on your database in SQL Server 2012,

image

Since this is disabled we will use SQL query to rename the database.

USE master;
GO
ALTER DATABASE DemoRename
Modify Name = DemoRenameDB ;
GO

image 

Now just refresh your Database and see the result,

image

Wednesday, October 23, 2013

How to use Ajax FilteredTextBoxExtender

Did you ever think of getting a ready made textbox with validation in ASP.NET? In this article I am going to explain you an Ajax control names FilteredTextBoxExtender. This control will help you to filter the user input without any additional script or coding.

Advantage of FilteredTextBoxExtender is there is not much configuration required. IT has only few properties.

1. TargetControlID—> You may specify the control you wanted to filter.

2. FilterType—> Here you mention what kind of filter you want to apply on your textbox control.

3. ValidChars—>As it’s name suggests you may enter the valid characters user supposed to enter in your textbox.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FilteredTextbox.aspx.cs" Inherits="Blog.FilteredTextbox" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        </ajaxToolkit:ToolkitScriptManager>
        <br />
        <asp:Label ID="Label1" runat="server" Text="Please Enter Only Numeric Value"></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <ajaxToolkit:FilteredTextBoxExtender ID="TextBox1_FilteredTextBoxExtender" runat="server" Enabled="True" TargetControlID="TextBox1" ValidChars="0123456789" FilterType="Numbers">
        </ajaxToolkit:FilteredTextBoxExtender>
    </div>
    </form>
</body>
</html>
Output will be like below,
FilterType="LowercaseLetters"

LowerCase

FilterType="UppercaseLetters"

UppercaseLetters

FilterType="Numbers"

Numbers

Hope you enjoyed this article. As usual your comments are always welcome.

Wednesday, October 2, 2013

How to insert comma separated value in a table using Stored procedure

Are you looking for a way to insert comma separated value in a table using SQL Stored Procedure? This article will help you to insert comma separated value in a different row. I thought I will write an article with full details because I used to see this question in Microsoft forums. 

Let’s start by creating a sample table first.

 

--Create table: 
CREATE TABLE tblNoOfAttempt(UserID INT IDENTITY,NoOfAttemp VARCHAR(50)) 

Since we have the table ready we will create the stored procedure to insert the comma separated value in our table.

 

-- Create Stored Procedure: 
Create PROCEDURE sp_InsertNoOfAttempt 
 
-- Add the parameters for the stored procedure here 
      @NoOfAttempt VARCHAR(100) 
AS 
BEGIN 
SET NOCOUNT ON; 
declare @XML xml 
SELECT @XML=CONVERT(xml,'<root><s>' + REPLACE(@NoOfAttempt,',','</s><s>') + '</s></root>') 
INSERT INTO tblNoOfAttempt 
SELECT [Value] = XM.SP.value('.','varchar(50)') 
FROM @XML.nodes('/root/s')XM(SP) 
END 
GO 

Now it’s the time to execute the stored procedure by passing some comma separated value.

-- Execute stored procedure by passing the comma separated value 
sp_InsertNoOfAttempt '8,7,10,9,5' 

Since the first field is an identity column we don’t need to pass the parameter for that. Value will be inserted automatically.

At last let’s see how the value is inserted in to he table by running select query.

-- Select the table values to see the out put 
select * from tblNoOfAttempt

Out put of the above query will be,

image

Saturday, September 21, 2013

0x800a138f - JavaScript runtime error: Unable to get property 'UI' of undefined or null reference

You might be wondering what is this error and what you have to do to resolve “0x800a138f - JavaScript runtime error: Unable to get property 'UI' of undefined or null reference” error. Here is the answer for you.

Reason for this error: This error normally occurs when you use ScriptManager, like below, because most of the controls from AjaxControlToolKit work using Ajax script unfortunately many Ajax scripts are not updated in ScriptManager.

<asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager> 

image

Solution to resolve this error: You have to use ToolkitScriptManager instead of ScriptManager. ToolkitScriptManager adds most of the updated Ajax Script. Your code after changing must be like below,

<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
 </asp:ToolkitScriptManager>

After changing to ToolkitScriptManager run your project and see the output.

Monday, September 2, 2013

The Report Server Installation Is Not Initialized (rsReportServer Not Activated)

This is one of the common error you may get when you rebuild or restore or upgrade your reporting server database and browse the report service manager URL. You may get the similar error when you browse the .rdl report also which was working earlier when your server was running fine.

To resolve this error you may follow one of the below steps,

Option 1:

  • Open Reporting Services Configuration Manager
  • Go to Encryption Keys
  • Delete Encrypted Content
  • Click on Delete

Option 2:

  • Go to Reporting Services Configuration Manager.
  • Go to "Encryption Keys" to backup the key.
  • Navigate to "Database" tab.
  • Click "Change Credentials" to reset the connections.

Now you will be able to browse the report without any issue.

Thursday, August 15, 2013

How to find all Saturday and Sunday of the Current Month in MS SQL

I have seen many people asking the question “How to show all Saturdays and Sundays of the current month” in forums, so I thought I will try which is the best and easiest solution for this requirement.

Here I am going to use common table expression (CTE) to show the week ends with the date of the month. Below is the actual query you can use to find all the weekends of the current month with date.

 
WITH CTE(DATE, DayOfTheMonth)
AS
(
SELECT DATEADD(DAY, -DAY(GETDATE()-1), GETDATE()), 1
UNION ALL
SELECT DATE+1, DayOfTheMonth+1 FROM CTE WHERE DayOfTheMonth < (SELECT DAY(DATEADD(DAY, -DAY(DATEADD(MM, 1, GETDATE())), DATEADD(MM, 1, GETDATE()))))
)
 
SELECT DATENAME(WEEKDAY, DATE) AS WeekDay_Name, DayOfTheMonth INTO #TempDateTable FROM CTE OPTION(MAXRECURSION 30)
 
SELECT * FROM #TempDateTable WHERE WeekDay_Name IN('Saturday', 'Sunday')
 
DROP table #TempDateTable
 
 

When you execute above query you will get the out put as

WeekDay_Name DayOfTheMonth
Saturday 3
Sunday 4
Saturday 10
Sunday 11
Saturday 17
Sunday 18
Saturday 24
Sunday 25
Saturday 31

Depends on the Month your DayOfTheMonth value will change. Since I am executing this in August 2013 it shows the records for that month.

image

Wednesday, August 14, 2013

List all tables in the SQL Database without Primary Key

Last week I was facing some issues with the application which I have been developing. Query was not working properly when somebody loaded huge test data in a table. when I checked the table I found that primary key was not created for that table even though it was not mentioned the database schema we have prepared. So I thought I will run a query to find out all the tables in the database which doesn’t have primary key.

Since I already created the query to find out all the tables without primary key in MS SQL database of course I have to share that with you also…

SELECT [schema_id] AS [Schema Name],[name] AS [Table Name], [type_desc] as [Table Type]
FROM sys.tables
WHERE OBJECTPROPERTY(OBJECT_ID,'TableHasPrimaryKey') = 0
 

Output of above query will be,

Table Names without primary key

Monday, August 5, 2013

How to enable Script debugging in web browser?

In this article I am going to explain you how to debug JavaScript or how to enable Script Debugging.

I have seen many people posting question in forum asking I am getting “Java script rut time error” and how to resolve this issue. Interestingly they post whole JavaScript also for the solution. With my experience it is bit hard to find out the actual issue in JavaScript if you are not able to find the exact line you are getting this exception.

Many people still not aware that we can debug JavaScript and find out the exact line where we are getting the script error.

To find the exact line where the exception is showing first we will enable the Script debugging in web browser. In this example I am using Internet Explorer.

To enable the JavaScript debugging in Internet Explorer follow below steps.
Open IE-->Go to Tools-->Internet Options—>Select Advanced Tab—>

Scroll down to Browsing section-->Un Check "Disable Script debugging (Internet Explorer)" and Uncheck "Disable script debugging (Other)" and Check "Display a notification about every script error".

Script Debugging

Click Ok to save the changes.

Now close your browser and open your web page and see the error message as pop up.

Script Debugging1

Click yes to open the script debugging and see in which line you are getting this error. Exact line you are getting this exception will be highlighted.

Script Debugging2

Now it will be very easy for you locate the line your script from your .aspx page.