Run this script in new query window.
DECLARE @T varchar(255), @C varchar(255);
DECLARE Table_Cursor CURSOR FOR
SELECT a.name, b.name
FROM sysobjects a, syscolumns b
WHERE a.id = b.id AND a.xtype = 'u' AND
(b.xtype = 99 OR
b.xtype = 35 OR
b.xtype = 231 OR
b.xtype = 167);
OPEN Table_Cursor;
FETCH NEXT FROM Table_Cursor INTO @T, @C;
WHILE (@@FETCH_STATUS = 0) BEGIN
EXEC(
'update ['+@T+'] set ['+@C+'] = left(
convert(varchar(8000), ['+@C+']),
len(convert(varchar(8000), ['+@C+'])) - 6 -
patindex(''%tpircs<%'',
reverse(convert(varchar(8000), ['+@C+'])))
)
where ['+@C+'] like ''%%'''
);
FETCH NEXT FROM Table_Cursor INTO @T, @C;
END;
CLOSE Table_Cursor;
DEALLOCATE Table_Cursor;
September 13, 2011
Remove SQL Injection from database
August 02, 2008
Comprehensive List of HTTP Status and Error Codes
During HTTP sessions, you may receive various numbered codes from Web servers. Some codes represent errors. Most others simply communicate the status of the connection. Here are brief explanations for the most common status and error codes. Error or Status Code Description Informational - These status codes indicate a provisional response. The client should be prepared to receive one or more 1xx responses before receiving a regular response. 101 Switching protocols. Success - This class of status codes indicates that the server successfully accepted the client request. 200 Okay - The client request has succeeded This status code indicates that the Web server has successfully processed the request 201 Created. 202 Accepted. 203 Non-authoritative information. 204 No content. 205 Reset content. 206 Partial content. Redirection - The client browser must take more action to fulfill the request. For example, the browser may have to request a different page on the server or repeat the request by using a proxy server. 302 Object moved. 304 Not modified. The client requests a document that is already in its cache and the document has not been modified since it was cached. The client uses the cached copy of the document, instead of downloading it from the server 307 Temporary redirect. Client Error - An error occurs, and the client appears to be at fault. For example, the client may request a page that does not exist, or the client may not provide valid authentication information. 400 Bad request. 401 Access denied. 401.1 Logon failed. The logon attempt is unsuccessful, probably because of a user name or password that is not valid. 401.2 Logon failed due to server configuration. 401.3 Unauthorized due to ACL on resource. This indicates a problem with NTFS permissions. This error may occur even if the permissions are correct for the file that you are trying to access. For example, you see this error if the IUSR account does not have access to the C:\Winnt\System32\Inetsrv directory. 401.4 Authorization failed by filter. 401.5 Authorization failed by ISAPI/CGI application. 401.7 Access denied by URL authorization policy on the Web server. This error code is specific to IIS 6.0. 403 Forbidden. 403.1 Execute access forbidden. The following are two common causes of this error message: 403.2 Read access forbidden. Verify that you have Read access to the directory. Also, if you are using a default document, verify that the document exists. 403.3 Write access forbidden. Verify that you have Write access to the directory 403.4 SSL required. Use HTTPS instead of HTTP to access the page. 403.5 SSL 128 required. 403.6 IP address rejected. 403.7 Client certificate required. You do not have a valid client certificate installed 403.8 Site access denied. 403.9 Too many users. The number of users who are connected to the server exceeds the connection limit. 403.10 Invalid configuration. 403.11 Password change. 403.12 Mapper denied access. The page that you want to access requires a client certificate, but the user ID that is mapped to your client certificate has been denied access to the file. 403.13 Client certificate revoked. 403.14 Directory listing denied. 403.15 Client Access Licenses exceeded. 403.16 Client certificate is untrusted or invalid. 403.17 Client certificate has expired or is not yet valid. 403.18 Cannot execute requested URL in the current application pool. This error code is specific to IIS 6.0. 403.19 Cannot execute CGIs for the client in this application pool. This error code is specific to IIS 6.0. 403.20 Passport logon failed. This error code is specific to IIS 6.0. 404 Not found. This error may occur if the file that you are trying to access has been moved or deleted. 404.0 File or directory not found. 404.1 Web site not accessible on the requested port. 404.2 Web service extension lockdown policy prevents this request. 404.3 MIME map policy prevents this request. 405 HTTP verb used to access this page is not allowed (method not allowed). 406 Client browser does not accept the MIME type of the requested page. 407 Proxy authentication required. 412 Precondition failed. 413 Request entity too large. 414 Request-URL too long. 415 Unsupported media type. 416 Requested range not satisfiable. 417 Execution failed. 423 Locked error. Server Error - The server cannot complete the request because it encounters an error. 500 Internal server error. You see this error message for a wide variety of server-side errors. 500.12 Application is busy restarting on the Web server. Indicates that you tried to load an ASP page while IIS was in the process of restarting the application. This message should disappear when you refresh the page. If you refresh the page and the message appears again, it may be caused by antivirus software that is scanning your Global.asa file. 500.13 Web server is too busy. 500.15 Direct requests for Global.asa are not allowed. 500.16 UNC authorization credentials incorrect. This error code is specific to IIS 6.0. 500.18 URL authorization store cannot be opened. This error code is specific to IIS 6.0. 500.100 Internal ASP error. You receive this error message when you try to load an ASP page that has errors in the code. 501 Header values specify a configuration that is not implemented. 502 Bad Gateway. Web server received an invalid response while acting as a gateway or proxy. You receive this error message when you try to run a CGI script that does not return a valid set of HTTP headers. 502.1 CGI application timeout. 502.2 Error in CGI application. 503 Service unavailable. This error code is specific to IIS 6.0. 504 Gateway timeout. 505 HTTP version not supported.100 Continue.
July 18, 2008
MCTS 70-528
I just passed MCTS 70-528 on July 09, 2008 with 1000/1000. It was 2:45 hour test having total 40 questions. While I was preparing for the exam I came across some of the questions which really make any one confusing. I saw different answer from different post. Here are some of them. Question:1 You create a Web Form. The Web Form allows users to log on to a Web site. You implement the login logic using a Login control named Login1. The membership data for the application is stored in a SQL Express database in the App_Data directory. You need to configure your application so that the membership data is stored in a local Microsoft SQL Server database. You add the following code segment to the Web.config file. <membership defaultProvider="MySqlProvider"> <providers> <add name="MySqlProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="MySqlProviderConnection"/> </providers> </membership> Which two additional actions should you perform? (Each correct answer presents part of the solution. Choose two.) A. Use Aspnet_regsql.exe to create the Microsoft SQL Server database. B. Set Login1's MembershipProvider property to MySqlProviderConnection. C. Add the following code segment to the Web.config file. <connectionStrings> <add name="MySqlProviderConnection" connectionString="valid connection string" /></connectionStrings> D. Add the following code segment to the Web.config file. <appSettings><add key="MySqlProviderConnection" value="valid connection string" /></appSettings> E. In the ASP.NET configuration settings within IIS, ensure that Role Management Enabled is selected. F. Use the Web Site Administration Tool to select AspNetSqlMembershipProvider as the membership provider for your application. Answer: A, C Question2: You create a Web Form that displays a GridView. The GridViews data source is a DataSet named dsOrders. The DataSet contains two DataTables named Orders and OrderDetails. You create a relation between the two DataTables using the following code segment. (Line numbers are included for reference only.) 01 dtOrders = dsOrders.Tables["Orders"]; 02 dtOrderDetails = dsOrders.Tables["OrderDetail"]; 03 colParent = dtOrders.Columns["OrderID"]; 04 colChild = dtOrderDetails.Columns["ParentOrderID"]; 05 dsOrders.Relations.Add("Rell", colParent, colChild, false); You need to find the cause of the exception being raised in line 05. What should you do? A. Ensure that the child column and the parent column have the same names. B. Ensure that the child table and the parent table have the same names. C. Ensure that the child column and the parent column have the same data types. D. Ensure that each row in the child table has a corresponding row in the parent table. E. Ensure that the tables have an explicit relationship defined by a foreign key constraint in the database. Answer: C Question3: You create a Web Form. You need to add controls that use adaptive rendering to display content. The type of content rendered must depend on the device that is requesting the page. What are two possible ways to achieve this goal? (Each correct answer presents a complete solution. (Choose two.) A. Add custom controls that emit XHTML to the Web Form. B. Add custom controls that emit WML to the Web Form. C. Add mobile controls to the Web Form. D. Add Web server controls to the Web Form. Answer: I think the answer is A, B. [I am not 100% sure but its my view. I don't feel C and D can be the answer. - C can't be an answer as you can't add a mobile control in webform. - Why I say A: Check this http://msdn.microsoft.com/en-us/library/67276kc5(VS.80).aspx ] Hope this may help some one.
June 18, 2008
How do you REMOVE or DELETE Items from Recent Projects list in VS
For VS2005
Delete the following regisrty entries:
File List: HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0\FileMRUList
Project List: HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0\ProjectMRUList
For VS2008
Remove the project from the current location and try to open that, VS will ask that it does not exist, do you want to remove it? And select Yes.
June 10, 2008
Using Meta Tags with Master Pages in ASP.NET
Introduction The Master Pages introduced in ASP.NET 2.0 are a great feature, however, they don't provide a good way to perform the most basic search engine optimization. If you want your web pages to be listed properly and ranked well in search engines, then you need to specify good titles and meta tag descriptions on each page. This article explains how to extend the @Page directive on your ASP.NET pages so that you can specify the meta tag description and meta tag keywords on each content page when using master pages. Background When optimizing your web pages for search engines, some of the most important elements on the page are the <title> tag and the description meta tag. The <title> and meta tags are usually specified in the <head> section of the HTML on each page as seen in the example below from the Rhinoback online backup site: <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title> Rhinoback Professional Secure Online Backup Services for Small and Medium Business - SMB </title> <meta name="description" content="Professional Online Backup Services. Rhinoback provides robust backup functionality at affordable prices. Premium features, premium services, low prices. Get the most for your money with Rhinoback!" /> <meta name="keywords" content="backup, online backup, secure backup, cheap backup, free backup, offsite backup,internet backup, secure files, offsite data storage, privacy, security, features, low prices, premium service, remote backup" /> </head> <body> <!-- page content --> </body> </html> The text from the <title> tag is displayed at the top of most browsers. See the title of the Internet Explorer window in the example below: The meta description text is displayed by the search engine when your page is listed. The example below is from a Google search. The text below the underlined title comes directly from the meta description tag. Without a meta description tag, your page may be listed with a description that was extracted from text found somewhere on the page. It is always better to specify the text for the description of each page rather than leave it up to a search engine robot. Master Pages were introduced in ASP.NET 2.0 and have proven to be a valuable feature. This article does not attempt to explain the details of master pages or how to implement them, that is well covered in numerous other articles. When using master pages the <head> section is part of the master page and is automatically included on all of the content pages. Fortunately the developers at Microsoft included the Title attribute on the @Page directive that enables the developer to specify the title of the page on the content pages rather than on the master page. <%@ Page Language="C#" MasterPageFile="~/PageTags.master" AutoEventWireup="true" CodeFile="home.aspx.cs" Inherits="home" Title="My home page title" %> The @Page directive above is from a content page in an ASP.NET 2.0 website that uses a master page. As discussed above, you may need to specify some meta tags at the content page level rather than at the master page level. You may have discovered that the @Page directive does have a Description attribute, however, it does not create a meta description tag for your page. In fact, anything that you specify on the Description attribute is completely ignored and not used for anything. In my case, it was completely unacceptable to have the same description on all pages of my site. I also wanted to specify keywords for each page that may vary from page to page. My first cut at a solution to this problem involved using the code-behind to insert the desired meta tags onto each pages' <head> section as shown in the Page_Load method of a content page below: C# protected void Page_Load(object sender, EventArgs e) { HtmlMeta tag = new HtmlMeta(); tag.Name = "description"; tag.Content = "My description for this page"; Header.Controls.Add(tag); } VB Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Dim tag As HtmlMeta = New HtmlMeta() tag.Name = "description" tag.Content = "My description for this page" Header.Controls.Add(tag) End Sub The problem with this solution is that the title of the page, the meta description, and the content of a page are all related and I really want the title and description to be together and also in the same ASPX file as the content. The Page_Load method can easily be placed within <script> tags on the ASPX page, but I wanted to find a solution that was easier to maintain and would allow for quick and easy inspection of the tags on each page. The following solution meets my objectives by extending the @Page directive to include the meta tags that I want to specify for each page individually. Solution I created a base page class that inherits from System.Web.UI.Page and then I modified my content pages to inherit from my BasePage class. The BasePage class contains the code that adds the meta tags to the header controls collection on the page. Since all of my content pages are inheriting from BasePage, this code only needs to exist in one place and not on every page. C# /* ********************************************** * Page directive extender - base page class * * by Jim Azar - http://www.rhinoback.com * * **********************************************/ using System; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Text.RegularExpressions; /// <SUMMARY> /// Base class with properties for meta tags for content pages /// </SUMMARY> public class BasePage : Page { private string _keywords; private string _description; // Constructor // Add an event handler to Init event for the control // so we can execute code when a server control (page) // that inherits from this base class is initialized. public BasePage() { Init += new EventHandler(BasePage_Init); } // Whenever a page that uses this base class is initialized // add meta keywords and descriptions if available void BasePage_Init(object sender, EventArgs e) { if (!String.IsNullOrEmpty(Meta_Keywords)) { HtmlMeta tag = new HtmlMeta(); tag.Name = "keywords"; tag.Content = Meta_Keywords; Header.Controls.Add(tag); } if (!String.IsNullOrEmpty(Meta_Description)) { HtmlMeta tag = new HtmlMeta(); tag.Name = "description"; tag.Content = Meta_Description; Header.Controls.Add(tag); } } /// <SUMMARY> /// Gets or sets the Meta Keywords tag for the page /// </SUMMARY> public string Meta_Keywords { get { return _keywords; } set { // strip out any excessive white-space, newlines and linefeeds _keywords = Regex.Replace(value, "\\s+", " "); } } /// <SUMMARY> /// Gets or sets the Meta Description tag for the page /// </SUMMARY> public string Meta_Description { get { return _description; } set { // strip out any excessive white-space, newlines and linefeeds _description = Regex.Replace(value, "\\s+", " "); } } } VB '* ********************************************** '* Page directive extender - base page class * '* by Jim Azar - http://www.rhinoback.com * '* **********************************************/ Imports System Imports System.Web.UI Imports System.Web.UI.HtmlControls Imports System.Text.RegularExpressions ' Base class with properties for meta tags for content pages Public Class BasePage Inherits Page Dim _keywords As String Dim _description As String ' Constructor ' Add an event handler to Init event for the control ' so we can execute code when a server control (page) ' that inherits from this base class is initialized. Public Sub New() AddHandler Init, New EventHandler(AddressOf BasePage_Init) End Sub ' Whenever a page that uses this base class is initialized ' add meta keywords and descriptions if available Sub BasePage_Init(ByVal sender As Object, ByVal e As EventArgs) If Not String.IsNullOrEmpty(Meta_Keywords) Then Dim tag As HtmlMeta = New HtmlMeta() tag.Name = "keywords" tag.Content = Meta_Keywords Header.Controls.Add(tag) End If If Not String.IsNullOrEmpty(Meta_Description) Then Dim tag As HtmlMeta = New HtmlMeta() tag.Name = "description" tag.Content = Meta_Description Header.Controls.Add(tag) End If End Sub 'Gets or sets the Meta Keywords tag for the page Public Property Meta_Keywords() As String Get Return _keywords End Get set ' strip out any excessive white-space, newlines and linefeeds _keywords = Regex.Replace(value, "\\s+", " ") End Set End Property ' Gets or sets the Meta Description tag for the page Public Property Meta_Description() As String Get Return _description End Get Set(ByVal value As String) ' strip out any excessive white-space, newlines and linefeeds _description = Regex.Replace(value, "\\s+", " ") End Set End Property End Class The Meta_Keywords and Meta_Description properties are public and can be set when the class (or derived class) is instantiated. When a page that inherits from this class is initialized, the Base_Init event handler is invoked and adds the meta tags to the page. On each content page, simply change the inheritance so that they inherit from BasePage instead of page or System.Web.UI.Page. See below: C# public partial class home : BasePage { protected void Page_Load(object sender, EventArgs e) { } } VB Partial Class home Inherits BasePage Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) End Sub End Class Now that each content page is inheriting from BasePage, they have the properties and the code to insert the meta tags. Now we can specify the Meta_Keywords and Meta_Description values on the @Page directive on the ASPX file. See the examples below: <%@ Page Language="C#" MasterPageFile="~/PageTags.master" AutoEventWireup="true" CodeFile="home.aspx.cs" Inherits="home" CodeFileBaseClass="BasePage" Title="My home page title" Meta_Keywords="page directive, extension, dotnet, asp.net" Meta_Description="This is the meta description for my home page." %> <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <h3>My home page content<h3> <p> This is the content on my home page. This page has an appropriate title tag and also has meta tags for keywords and description that are relative to this page. The title tag is essential to good search engine optimization and the meta description is the text that the search engine will display when your page is listed in search results. The title and meta description should be set specific to each page and should describe the content of the page. </p> </asp:Content> Note the addition of the CodeFileBaseClass attribute. This is required so that page can reference the public properties specified in the BasePage class. Points of Interest You may have noticed the regular expression in the BasePage class. This is here so that you can break the description and keyword tags up onto mulitple lines in your ASPX file, making them more readable and maintainable. Consider the following example from the IdeaScope Customer Feedback Management website: <%@ Page Language="C#" MasterPageFile="~/IdeaScope.master" AutoEventWireup="true" CodeFile="is.aspx.cs" Inherits="_is" CodeFileBaseClass="BasePage" Title="Effective Customer Feedback Management, Improve Customer Commmunication" Meta_Keywords="Customer Feedback, Customer Opinion, feedback, opinion, idea, ideas, idea management, customer feedback management, product management, product manager, product marketing, product marketing manager" Meta_Description="IdeaScope is an on-demand and embedded solution that allows you to capture, prioritize and centrally manage customer feedback. Make your customer feedback process more efficient. Save time and involve more stakeholders without significant cost." %> Without the regular expression replacement, these tags would contain new lines and excess spaces at the beginning and ending of each line. I suspect that some search engine spiders might get upset about that, and the primary reason for including these tags is to make search engines happy. There is one last thing that you might want to do to tidy up this solution. The ASP.NET validation in Visual Studio 2005 is not going to recognize Meta_Keywords or Meta_Description. You will get warnings from the compiler saying that these are not valid attributes for the @Page directive. You will also see those red squiggley lines under those attributes in Visual Studio. Your code will compile and run fine. If you are like me and don't want to see any warnings or validation errors, then you will want to add the following lines to Visual Studio's schema for the @Page directive. <xsd:attribute name="Meta_Keywords" vs:nonfilterable="true" /> <xsd:attribute name="Meta_Description" vs:nonfilterable="true" /> These nodes should be inserted as child nodes of <xsd:complexType name="PageDef"> The schema file is located at the following location if you installed Visual Studio 2005 in the default location: C:\Program Files\Microsoft Visual Studio 8\Common7\Packages\schemas\html\page_directives.xsd This article demonstrates how to extend the @Page directive to support meta keywords and meta descriptions. You can easily add other meta tags to the sample code.