Translate

Tuesday 25 December 2012

CLR integration in sqlserver

http://www.codeproject.com/Articles/19502/A-T-SQL-Regular-Expression-Library-for-SQL-Server:

Step 1

--Enable CLR Integration
exec sp_configure 'clr enabled', 1
GO
RECONFIGURE
GO


Step 2:

CREATE ASSEMBLY [SqlRegEx] FROM 'C:\Project\SqlRegEx.dll' WITH PERMISSION_SET = SAFE

Step 3:

CREATE FUNCTION [dbo].[ufn_RegExIsMatch]
(@Input NVARCHAR(MAX), @Pattern NVARCHAR(MAX), @IgnoreCase BIT)
RETURNS BIT
AS EXTERNAL NAME SqlRegEx.[SqlClrTools.SqlRegEx].RegExIsMatch

Note:


SELECT dbo.ufn_RegExIsMatch('Hello World', 'w', 1) --Ignores Case
SELECT dbo.ufn_RegExIsMatch('Hello World', 'w', 0) --Case Sensitive


Example:
Find if Extended Acsii value
select * from TableName where dbo.ufn_RegExIsMatch(ColumnName,'[^\u0000-\u007F]',0 )=1

-------------------------------------------------------------------------------------------------------


Remove HTML tags from strings using the SQL Server CLR








Thursday 6 December 2012

SQL Server


ALTER DATABASE Compatibility Level (Transact-SQL) (Ex: Enable pivot table)

ALTER DATABASE database_name 
SET COMPATIBILITY_LEVEL = 100

Note: 
        80 = SQL Server 2000 
        90 = SQL Server 2005 
        100 = SQL Server 2008 and SQL Server 2008 R2
        110 = SQL Server 2012

Wednesday 5 December 2012

XCode for MAC

The Xcode developer tools package provides everything you need to create great applications for Mac, iPhone, and iPad.

The Xcode toolset includes the amazing Xcode IDE, with the Interface Builder design tool and Apple LLVM compiler fully integrated. 




Xcode IDE:


Designed from the ground up to take advantage of the newest Apple technologies, Xcode integrates all the tools you need. The unified interface smoothly transitions from composing source code, to debugging, and even to designing your next stunning user interface, all within the same window.

The Xcode workspace is all about keeping you focused. As you type, Live Issues will immediately alert you to coding mistakes, displaying a message bubble beside your code for more detail. Hit the Run button to launch your Mac app, or upload the app to your test device, and immediately start debugging. Hover the mouse pointer above a variable to inspect its value at runtime, never having lost your place in the editor.

Apple LLVM Compiler

Apple’s next generation compiler technology, the Apple LLVM compiler, does more than build your app. Apple LLVM technology is integrated into the entire development experience. The same parser used to build C/C++ and Objective-C powers Xcode’s indexing engine, providing incredibly accurate code completions. As you work, Apple LLVM is constantly evaluating what you type, identifying coding mistakes that Xcode shows as Live Issues, and thinking ahead for ways to Fix-it for you. Other compilers can tell you what is wrong — Apple LLVM can make it right.

That s all....

-> it' s user friendly for mac OS. 
-> Easy to development and so on.....

Saturday 17 November 2012

Useful blog spot link

Update Panel and Callback Panel


AJAX Page - UpdatePanel


CallbackPanel has 2 elements:
  • content element can contain contain html, js, css and other server controls - like Obout Calendar, Obout EasyMenu, ASP.NET controls (ASP Textbox, ASP DropDownList, etc.).
  • loading element is optional and it can include the html to display while the panel is loading.
    If ommited, a default "Loading..." text is shown and all styles from content element are applied to theloading element.
    It is visible only when the callback panel is updated using client-side UpdatePanel method.
Both content and loading elements can contain style definitions. 


<oajax:CallbackPanel runat="server" ID="callbackPanel1">

<content style="border:1px solid gray;width:400px;height:200px">

some content

</content>

<loading style="border:1px solid red;width:400px;height:200px">

Loading...please wait

</loading>

</oajax:CallbackPanel>

---------------------------------------------
It is very useful to load dynamic scripts, dynamic stylesheets, dynamic controls, etc. 

The update of the panel is done without reloading the page. 

Client-side update 
ob_post.UpdatePanel("callbackPanel1"); 
ob_post.UpdatePanelInContainer("callbackPanel1", "container"); 
ob_post.UpdatePanelFromPage("callbackPanel1", "container", "callbackPanels.aspx"); 
ob_post.UpdateAllPanels(); 

Server-side update 
UpdatePanel("callbackPanel1"); 
UpdatePanel("callbackPanel1", "container"); 
UpdateAllPanels(); 
--------------------------------------------------------------------
Update Callback Panel specified by id. 

For example, you can use the next lines: 

Client-side update
        ob_post.UpdatePanel("callbackPanel1"); 
  

Server-side update
        UpdatePanel("callbackPanel1"); 
  

Example 1 - Callback Panel contain html, css and ASP DataList control.
<%@ Register TagPrefix="oajax" Namespace="OboutInc" Assembly="obout_AJAXPage" %>

        <oajax:CallbackPanel runat="server" ID="callbackPanel1">
            <content style="border: gray 1px solid;">
                <style>
                .divItem
                {
                    border-bottom:1px solid gray;
                    font-size:9px;
                    width:130px;
                    padding-top:4px;
                    padding-bottom:4px;
                }
                </style>
                <b>My List</b>
                <asp:DataList id="dataList1" runat="server">
                    <ItemTemplate>
                        <div class="divItem">
                            some item content
                        </div>
                    </ItemTemplate>
                </asp:DataList>
            <content>
            <loading style="border: gray 1px solid;">
                Loading...please wait
            </loading>
        </oajax:CallbackPanel>
    

See also live UpdatePanel Example


Example 2 - Callback Panel contain ASP Literal control.
<%@ Register TagPrefix="oajax" Namespace="OboutInc" Assembly="obout_AJAXPage" %>

        <oajax:CallbackPanel runat="server" ID="callbackPanel1">
            <content style="border: gray 1px solid;">
                <asp:Literal id="serverTime" Runat="server"></asp:Literal>
            </content>
            <loading style="border: gray 1px solid;">
                Loading...please wait
            </loading>
        </oajax:CallbackPanel>
   

Example 3 - multiple Callback panel.
Client-side update
        ob_post.UpdateAllPanels(); 
  

Server-side update
        UpdateAllPanels(); 

public void UpdateAllPanels()
        UpdatePanel("CallBackPanel1");
        UpdatePanel("CallBackPanel2");
}

<%@ Register TagPrefix="oajax" Namespace="OboutInc" Assembly="obout_AJAXPage" %>
        <!-- CallbackPanel1-->
        <oajax:CallbackPanel runat="server" ID="callbackPanel1">
            <content style="border: gray 1px solid;">
                <span style="color:red">
                    <asp:Literal id="serverMillisecond" Runat="server"></asp:Literal>
                </span>
            </content>
        </oajax:CallbackPanel>

        <!-- CallbackPanel2-->
        <oajax:CallbackPanel runat="server" ID="callbackpanel2">
            <content style="border: gray 1px solid;">
                <asp:Literal id="serverTime" Runat="server"></asp:Literal>
            </content>
        </oajax:CallbackPanel>


Example 4- Callback Panel inside Update panel.
<%@ Register TagPrefix="oajax" Namespace="OboutInc" Assembly="obout_AJAXPage" %>
 <tr>
    <td>
         <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
         <ContentTemplate>
           <oajax:CallbackPanel ID="CallBackPanel1" runat="server">
             <Content>
                 <table border="0" width="100%">
                  <tr>
                     <td>
 age ID="imgIndication" runat="server" Height="15px" ImageUrl="~/images/icon-delete.gif" Width="15px" />
                     </td>
                  </tr>
                </table>
              </Content>
      </oajax:CallbackPanel>
    </ContentTemplate>
   </asp:UpdatePanel>
  </td>
 </tr>

Server-Side Update
    UpdatePanel("callbackPanel1"); 


Friday 16 November 2012

Alert Message from CodeBehind

1. How to Redirect a page after clicking OK of javascript alert box.

Way 1:

C# code behind:
string strScript = "<script>";
strScript += "alert('Type your message here');";
strScript += "window.location='TestPage.aspx';";
strScript += "</script>";
this.ClientScript.RegisterStartupScript(this.GetType(), "Startup", strScript);

Way 2:

 Response.Write("<script>alert('Successfully changed')</script>");
 Response.Write("<script>window.location.href='Default.aspx';</script>");

Way 3:

 ScriptManager.RegisterStartupScript(page, page.GetType(), "err_msg", "alert('" + error + "'); window.location='newpage.aspx';", true);

2. Alert message from Codebehind:

Way 1:


   ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Success');", true);


Way 2:

  Page.ClientScript.RegisterStartupScript(this.GetType(), "key", "alert('No Records Available');", true);


Way 3:
If we have used Update Panel, Use following code.

 ScriptManager.RegisterStartupScript(this.Page, typeof(UpdatePanel), "key", "alert('Success');", true);

2. Confirmation Message:


<script type="text/javascript">
        function Confirm(id, des) {
            // debugger;
            try {
                if (document.getElementById(id).value != "") {
                    var r = confirm("This is new Code.Do you want add this code?");
                    if (r == true) {
                        document.getElementById(des).value = "";
                        document.getElementById(des).focus();
                        return true;

                    }
                    else {
                        document.getElementById(id).value = "";
                        document.getElementById(id).focus();
                        return true;
                    }
                    return false;
                }
            }
            catch (e) {
            }
        }
     
    </script>

Thursday 15 November 2012

Java Script Function

1. how to display block or none for control in javascript

<tr id="trBrowse" runat="server" style="display: none;">
      <td></td>
</tr>

trBrowse.Style.Add("display", "block");

How to get open folders list using C#?


To Open a particular folder in Explorer, just:
System.Diagnostics.Process.Start(@"explorer.exe", @"C:\Windows");
In fact, as Explorer is the asscoaited handler for folder, that could be written as:
System.Diagnostics.Process.Start(@"C:\Windows");
or
 string path="D:\\Test";
 System.Diagnostics.Process.Start("explorer.exe", path);


CheckForDuplicates confirmation message

protected void SaveButton_Click(object sender, EventArgs e)
{
    try
    {
        if (CheckForDuplicates())
        {
            //proceed normally
        }
    }
}

private bool CheckForDuplicates()
{
    //check database

            if (/*there are duplicates*/)
            {
                string message = "A duplicate name exists. Would you like to continue?";
                string scriptString = "<script language='javascript' 
                    type='text/javascript'>" + "return confirm('" + message + "');</script>";

                ScriptManager.RegisterStartupScript(this, this.GetType(), 
                    "script", scriptString, false);

                //here i would like to return their confirmation
            }
        }
    }
    return true;
}

Find Extented Ascii Value using javascript


<script type="text/javascript">
function CheckAll() {
var Titleid = document.getElementById('ID');
            var tit = Titleid.value;
            var T = [];
            for (var i = 0, j = Titleid.value.length; j--; i++) {
                T[i] = tit.charCodeAt(i);
                if (T[i] > 128) {
                    alert("Ascii found: " + String.fromCharCode(T[i]));
                    document.getElementById('ID').focus();
                    return false;
                }
            }

  return true;
        }
 </script>


Thursday 4 October 2012

Web Config Helps


1. Connection String:


<connectionStrings>
    <add name="constr"  connectionString="Initial catalog=DB_Name;uid=sa;pwd=Password;Data Source=Server_IP" providerName="System.Data.SqlClient"/>
  </connectionStrings>


2.  Error - Operation is not valid due to the current state of the object

Whenever a postback is done, this error occurs when form fields are very large (text) in number. The stack trace is:
at System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded() at System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding) at System.Web.HttpRequest.FillInFormCollection()
By default, the maximum value of MaxHttpCollection is 1000.
To solve this error, increase the MaxHttpCollection value. Try adding the following setting in yourweb.config's <appsettings> block.
  <configuration>
      <appSettings>
    <add key="aspnet:MaxHttpCollectionKeys" value="9999" />
  </appSettings>
</configuration>
It can solve your problem. If you have very large records on your page, say 600 records in a grid, and you click on Submit, then increase the value of MaxHttpCollection.

2. EnCrypt and Decrypt of Connection String in webconfig:

Encrypt connectionStrings in web.config of IIS based site
 
http://www.codeproject.com/images/minus.gif Collapse | Copy Code
aspnet_regiis.exe -pe "connectionStrings" -app "/SampleWebSite"
Here –pe indicates that the application is built as IIS based site. Second argument connectionStrings is the name ofconfiguration section needs to be encrypted. The Third argument -app indicates virtual directory and last argument is the name of virtual directory where application is deployed.
 
Decrypt connectionStrings in
 web.config of IIS based site
 
http://www.codeproject.com/images/minus.gif Collapse | Copy Code
aspnet_regiis.exe -pd "connectionStrings" -app "/SampleWebSite"
Till now we learned how to encrypt and decrypt connectionStrings section in web.config file using aspnet_regiis.exe command line tool now I will explain code behind method to encrypt and decrypt the connection string section inweb.config.

3. How to: Set the Culture and UI Culture for ASP.NET Web Page Globalization
Or

CurrentCulture incorrectly defaulting to en-US in ASP.net


<globalization uiCulture="en" culture="en-US" />

4. How to increase Session Timeout:

<httpRuntime executionTimeout="999999" maxRequestLength="2097151"/>

5. How to Set: Dundas chart Temporary location, Default Excel version , Date and Time in Web config.

<appSettings>
    <add key="CommandTimeout" value="60000"/>
    <add key="DefaultDate" value="12/30/1899"/>
    <add key="DefaultTime" value="12/30/1899"/>
    <add key="OLEDBConnection2" value="Microsoft.Jet.OLEDB.4.0"/>
    <add key="OLEDBConnection" value="Microsoft.ACE.OLEDB.12.0"/>
    <add key="ExcelVersion" value="Excel 12.0"/>
    <add key="ChartHttpHandler" value="Storage=memory;Timeout=180;Url=~/temp/;"/>
</appSettings>