Sql Server Database Backup

August 29, 2010

DECLARE @name VARCHAR(50) -- database name
DECLARE @path VARCHAR(256) -- path for backup files
DECLARE @fileName VARCHAR(256) -- filename for backup
DECLARE @fileDate VARCHAR(20) -- used for file name

SET @path = 'C:\Backup\'

SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112)

DECLARE db_cursor CURSOR FOR
SELECT name
FROM master.dbo.sysdatabases
WHERE name NOT IN ('master','model','msdb','tempdb')

OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @name

WHILE @@FETCH_STATUS = 0
BEGIN
SET @fileName = @path + @name + '_' + @fileDate + '.BAK'
BACKUP DATABASE @name TO DISK = @fileName

FETCH NEXT FROM db_cursor INTO @name
END

CLOSE db_cursor
DEALLOCATE db_cursor

Cursor Components

Based on the example above, cursors include these components:

  • DECLARE statements – Declare variables used in the code block
  • SET\SELECT statements – Initialize the variables to a specific value
  • DECLARE CURSOR statement – Populate the cursor with values that will be evaluated
    • NOTE – There are an equal number of variables in the DECLARE <cursor_name> CURSOR FOR statement as there are in the SELECT statement.  This could be 1 or many variables and associated columns.
  • OPEN statement – Open the cursor to begin data processing
  • FETCH NEXT statements – Assign the specific values from the cursor to the variables
    • NOTE – This logic is used for the initial population before the WHILE statement and then again during each loop in the process as a portion of the WHILE statement
  • WHILE statement – Condition to begin and continue data processing
  • BEGIN…END statement – Start and end of the code block
    • NOTE – Based on the data processing multiple BEGIN…END statements can be used
  • Data processing – In this example, this logic is to backup a database to a specific path and file name, but this could be just about any DML or administrative logic
  • CLOSE statement – Releases the current data and associated locks, but permits the cursor to be re-opened
  • DEALLOCATE statement – Destroys the cursor

FloatingPoblem

August 18, 2010

When we want to float a html control above the object control then we will not be able to float it by
increase the z-index property but it can be possible if we use both as object

<OBJECT ID=’ctl00_MasterContentplaceholder_newdate_obj’
DATA=’objNew.html’ style=’z-index:12; width:100%; position:absolute; height:5px;’
TYPE=’text/x-scriptlet’ >
</OBJECT>

In the above example in between object we fetch html and do needed coding there.

In other way it can also be possible by taking iframe instead of object

<iframe src=”yourwebpage.html” name=”anyname” width=”200″ height=”150″ align=”default”></iframe>

Howto run a query from mysql command prompt

June 6, 2010

Howto run a query from mysql command prompt

We need to follow the following steps to run database query from mysql comand prompt
1>Go to Mysql comand promt.
2>Specify the connecting password.
3>Now create a sql file which we can use as source file to run all the query.
That is our comand will be =>
source (The sql file location where everything specified)
4>The sql file should be look like..

rnd_db_ddl.sql
drop database if exists rnd_db;

create database rnd_db;
use rnd_db;

\. C:/Projects/rnd_db/organization.sql=>this comand will execute the organization.sql
from the mention path.

Organization.sql should be look like this
organization.sql
drop table if exists organization;
create table `organization` (
`organization_id` int not null auto_increment,
`organization_name` varchar(200) not null,
`is_active` tinyint(1) not null,
`address_line1` varchar(255) not null,
`address_line2` varchar(255) default null,
`city` varchar(100) not null,
`state` varchar(100) not null,
`country` varchar(100) not null,
`zipcode` varchar(15) default null,
`telephone_country_code` int default null,
`telephone_area_code` int default null,
`telephone` int default null,
`mobile_country_code` int default null,
`mobile` int default null,
`fax_country_code` int default null,
`fax_area_code` int default null,
`fax` int default null,
`url` varchar(255) default null,
`created_by` int  not null,
`date_created` timestamp not null default current_timestamp,
`updated_by` int  not null,
`date_updated` timestamp not null,

constraint organization_pk primary key  (`organization_id`),
key `organization_ix` (`organization_id`)
) engine=innodb;

INSERT INTO `organization` (`organization_id`,`organization_name`,
`is_active`,`address_line1`,`address_line2`,`city`,`state`,`country`,
`zipcode`,`telephone_country_code`,`telephone_area_code`,
`telephone`,`mobile_country_code`,`mobile`,`fax_country_code`,
`fax_area_code`,`fax`,`url`,`created_by`,`date_created`,`updated_by`,
`date_updated`) VALUES (1,’Christian Medical Hospital’,1,’R.T.Nagar’,”,
‘Bangalore’,'Karnataka’,'India’,’560032′,91,80,23544328,0,0,0,0,0,
‘www.cmc.com’,1,’2009-11-12 00:00:00′,1,’2009-11-12 00:00:00′);

March 12, 2010

How to use JSdoc

JSDoc is meant to do for Javascript, what Javadoc does for Java.

It does.

We can download and install JSDoc easily:

1. Download JSDoc
2. Expand the tgz.gz file (I use Winrar)
3. Optional – I copy the jsdoc folder to my D: drive to make things easier
4. Reminder – you need a perl runtime installed.  ActivePerl is recommended
5. Open up a command prompt
6. Change to your JSDoc folder (mine is D:\JSDoc-1.10.2\)
7. Run it: “perl jsdoc.pl test.js” (to test it against the built in JS file)

JSDoc is like the following image

In the following all the parameter are showing..

ag Reference

The following is a summary of the supported tags (‘@’-attributes) that are supported by JSDoc. For actual examples of the usage of these tags, please see the test.js JavaScript file that is included in the JSDoc distribution.

@param Provide information about a function parameter. A datatype indicator can be added between curly braces with this tag, as follows:

        /**           * @param {String} paramName This is a string parameter           */
@argument Synonym for @param
@return Provide information about the return value of a function.
@returns Synonym for @return
@author Provide information about the author of a JavaScript file or a function.
@deprecated Signify that a function or class is deprecated, and should not be used if possible.
@see Link to another class or function that is of importance to the current class or function. This tag can take several forms.

To link to another method within the same class:

        @see #methodName

To link to another class:

        @see ClassName

To link to a specific method of another class:

        @see ClassName#methodName
@version Show the version number of the current file or class
@requires Define a dependency upon another class. The syntax for this tag is as follows:

        @requires OtherClassName This is text to be shown
@throws Show that a method can throw a certain type of exception. The syntax for this tag is:

        @throws ExceptionType This is the label text
@exception Synonym for @throws
@link This is a powerful tag that can be used to link to a large number of other pages. It is also the only tag that can be used in the description text of a documentation string before the ‘@’-tag section. The usage is very similar to that of the @see tag, but the entire tag is wrapped in curly braces. For example:

        /**           * This utility method is also a member of the {@link String} class,            * in the form of the {@link String#utility} method.            */
@fileoverview This is a special-use tag. If the first block of documentation in a file starts with a @fileoverview tag, the rest of the documentation block will be used to provide a file overview in the documentation.
@class This tag is used in a constructor’s documentation block to provide information about the actual class. The included documentation will then not be included in the constructor’s documentation.
@constructor Signify that a function is the constructor for a class.
@type Show the return type of a function. For example:

        /**           * This function returns a String.           * @return The name of the current user           * @type String           */
@extends Used to show that a class is a subclass of another class. JSDoc is often quite good at picking this up on its own, but in some situations this tag is required.
@private Signify that a function or class is private. Private classes and functions will not be available in the documentation unless JSDoc is run with the –private commandline option.
@final Flag a value as being a final (constant) value.
@member Show that a function is a member of a given class:

        /**           * @member MyClass           */   	function SomeFunc(){  	}
@ignore Tell JSDoc to totally ignore this method.
@base Force JSDoc to view the current class constructor as a subclass of the class given as the value to this tag:

       /**          * This is a subclass of Shape          * @constructor          * @base Shape          */         function Circle(){             // ...         }
@addon Mark a function as being an “addon” to a core JavaScript function that isn’t defined within your own sources, as shown below:

	/**   	 * This is an addon function to SomeCoreClass which is           * not defined within our own sources.   	 * @addon  	 */  	SomeCoreClass.someFunction = function(){               // ...  	}
@exec Experimental!

Force JSDoc to “execute” this method as part of its preprocessing step, in the same way that class contructors are executed. This can allow attributes to be added to a class from within a function.

Security Issues

February 13, 2010

Security Issues with ViewState

ViewState in ASP.NET can easily be tampered cause the ViewState data is not encrypted. Therefore, please do not store important data or information in ViewState. But if you really need to store the important data in Viewstate, few steps can be used to protect and encrypt the ViewState Data.
1. Enable ViewState Mac in page directives or in the web.config level

<%@Page EnableViewStateMAC=true %>

2. Set the machine.config key by using validation such as 3Des or Sha1. Sha1 is more secured compare to 3Des as it produces a larger hash than MD5 and is cryptographically stronger.

You need to edit your machine.config files like this.

<machineKey validation="3Des" validationKey="AutoGenerate,IsolateApps"/> or
<machineKey validation="SHA1" validationKey="AutoGenerate,IsolateApps"/>

If you are running WebFarm on your machine, you cannot use AutoGenerate in your validationKey, hence you must set the same key for all your web farm machine. Otherwise, ViewState generated from one machine could not be POSTed back to a machine farm with different key!. The keys should be 128 characters long(the maximum) and generated totally by random means.

Create XMl

February 13, 2010

How to create xml

To create xml we need to do following steps=>

1)First include the name i)System.Xml ii)System.IO iii)System.Text.

2)create writer object

>XmlTextWriter writer = new XmlTextWriter(Server.MapPath(“xml/userInfo.xml”), Encoding.UTF8);
In Server.MapPath we specify the path where we would like to create xml file.
statr to write by writer.WriteStartDocument();
writer.WriteStartElement(“userInfo”); this specify strat element with element userInfo
writer.WriteElementString(“urlReferrer”, “none”);this specify sub element with element urlReferrer and value none
writer.WriteAttributeString(“timeVisited”, DateTime.Now.ToString());this specify a element attribute with timeVisited
writer.WriteEndElement(); this specify end of a element
writer.WriteEndDocument(); this specify end of a document.
writer.Close(); this specify close of a document.

Store Procedure example

December 18, 2009

CREATE PROCEDURE [dbo].[test_sp_add_user]
AS

DECLARE @UserPKID BIGINT

INSERT INTO test_user
(FirstName,LastName,Address1,Address2,
Country,EmailID,Password,Status)
VALUES
(@FirstName,@LastName,@Address1,@Address2,
@Country,@EmailID,@Password,@Status)

SET @UserPKID = @@identity
GO

(
@FirstName VARCHAR(255),
@LastName VARCHAR(255),
@Address1 VARCHAR(255),
@Address2 VARCHAR(255),
@Country VARCHAR(255),
@EmailID VARCHAR(255),
@Password VARCHAR(255),
@Status BIT
)

CREATE PROCEDURE [dbo].[test_sp_delete_user]
(
@MemberID nvarchar(1000)
)
AS
exec(‘DELETE FROM kjaya_user WHERE MemberID IN (‘ + @MemberID + ‘) ‘)
GO

CREATE PROCEDURE [dbo].[test_sp_update_user]
(
@MemberID BIGINT,
@FirstName VARCHAR(255),
@LastName VARCHAR(255),
@Address1 VARCHAR(255),
@Address2 VARCHAR(255),
@Country VARCHAR(255),
@EmailID VARCHAR(255),
@Password VARCHAR(255),
@Status BIT
)
AS
UPDATE test_user
SET
FirstName = @FirstName,
LastName = @LastName,
Address1 = @Address1,
Address2 = @Address2,
Country = @Country,
EmailID = @EmailID,
Password = @Password,
Status = @Status
WHERE MemberID = @MemberID
GO

Add the following code to the section to redirect the user to a custom page:

This setting goes in your web.config file. It affects the entire application, though… I don’t think you can set it per page.

“xxx” is in KB. The default is 4096 (= 4 MB).

Cursor

November 2, 2009

Cursors can be considers as result sets which allow a user to move through each record one by one.
Whenever we find some situation where we need to process each record individually we can use cursors.

In order to work with a cursor we need to perform some steps in the following order

1. Declare  cursor
2. Open cursor
3. Fetch row from the cursor
4. Process fetched row
5. Close cursor
6. Deallocate cursor

First of all we need to declare a cursor with the help of Declare statement and in
order to specify the result set contained by this cursor we use Select statement.
For example we can define a cursor named “MyCur” and we can use a table named Users
having two columns UserName, and Password.

Declare MyCur Cursor
For
Select * From Users

Open MyCur

Now, fetch first row from this cursor and loop through the cursor records until the specified criteria is found

Declare @UserName Varchar(50)

Declare @Password Varchar(50)

Fetch Next From Cursor Into @UserName, @Password

While @@Fetch_Status = 0

Begin

–Check if appropriate row was found then process it

–Othewise

–Fetch the next row as we did in the previous fetch  statement

End

When we have worked with the cursor, we’ll close it and deallocate it so that there will remain no reference to this cursor any more.

Close MyCur
Deallocate MyCur

Googl API

August 23, 2009

Google search API URL

http://code.google.com/apis/ajaxsearch/signup.html?url=http://localhost/GoogleAPI/&key=ABQIAAAAfFLlcMdJpi-GA8PmfutjlRRqMtI6TmfFpjE_nNUIeqypmSKrtRSpgusRxFNPdQYEKe8akLUsMtw9Yg

Search API Key

localhost key

ABQIAAAAfFLlcMdJpi-GA8PmfutjlRRqMtI6TmfFpjE_nNUIeqypmSKrtRSpgusRxFNPdQYEKe8akLUsMtw9Yg

WordPress Information

July 28, 2009

WP_MEMORY_LIMIT=>memory_limit=>32M

ABSPATH=>Root Path=>root/wp-load.php

WPINC =>/wp-includes=>root/wp-admin/gears-manifest.php

FUNCTION
is_home()=>root/wp-includes/query.php

post_class()=>root/wp-includes/post-template.php=>Set the class of the post title.
have_posts()=>root/wp-includes/query.php
the_post()=>root/wp-includes/query.php=>For the post FUnction
setup_postdata($post)=>root/wp-includes/query.php=>Just Fecth the content and set no of pages.
process_posts()=>root/wp-admin/import/mt.php

the_title()=>root/wp-includes/post-template.php=>Just echo the title
get_the_content()=>root/wp-includes/post-template.php=>Fetch The Content

the_content()=>root/wp-includes/post-template.php=>Just echo the COntent
get_the_title()=>root/wp-includes/post-template.php=>Fetch The title

the_category()=>root/wp-includes/category-template.php=>Just echo the COntent
get_the_title()=>root/wp-includes/post-template.php=>Fetch The title

get_template_directory_uri()=>root/wp-content/themes/default/
dynamic_sidebar()=>root/wp-includes/widgets.php=>True/False

ajax_calendar()=>root/wp-content/plugins/ajax-calendar2/models/calender.php

wp_widget_calendar()=>root/wp-includes/widgets.php=>For Fetching Calender
get_calendar()=>root/wp-includes/general-template.php=>For Fetching Record With Calender
get_calendar()=>root/wp-includes/general-template.php=>For Setting css to the date for a post.
wp_widget_pages()=>root/wp-includes/widgets.php=>For Fetching Pages
wp_widget_links()=>root/wp-includes/widgets.php=>For Fetching Links
wp_widget_meta()=>root/wp-includes/widgets.php=>For Fetching Meta Tags
wp_widget_search()=>root/wp-includes/widgets.php=>For Fetching Search Function
get_search_form()=>root/wp-includes/general-template.php=>For Fetching Search Form
wp_widget_recent_entries()=>root/wp-includes/widgets.php=>For Get Widget Recent Entries
wp_widget_tag_cloud()=>root/wp-includes/widgets.php=>For Get Tag Function
wp_widget_archives()=>root/wp-includes/widgets.php=>For Get Archive information

Customize Calender
ec3_get_calendar()=>root/wp-content/plugins/event-calendar/template-functions.php
ec3_get_calendar_nav()=>root/wp-content/plugins/event-calendar/template-functions.php

wp_widget_categories()=>root/wp-includes/widgets.php=>For Get Categories
wp_list_categories()=>root/wp-includes/category-template.php=>For Fetching all categories Categories
get_category_link()=>
walk_category_tree()=>root/wp-includes/category-template.php=>Just calling the function to go through the category.
walk()=>root/wp-includes/classes.php=>=>Go through the category
display_element=>root/wp-includes/classes.php=>Display the category element.

Customize Function
wp_list_customized_categories()=>root/wp-includes/category-template.php=>customized categories Categories
walk_customized_category_tree()=>root/wp-includes/category-template.php=>Just calling the function to go through the
walk_customize()=>root/wp-includes/classes.php=>Go through the category.
start_customized_el()=>root/wp-includes/classes.php=>Fetch element to display category.

For Calender
go_next()=>root/wp-content/plugins/event-calendar/ec3.js=>For ajax javascript function.
loadDates()=>root/wp-content/plugins/event-calendar/ec3.js=>For ajax javascript function.
process_xml()=>root/wp-content/plugins/event-calendar/ec3.js=>Ready state function is call.
ec3_Popup.add_tbody()=>root/wp-content/plugins/event-calendar/popup.js=>79 line.
ec3_filter_query_vars()=>root/wp-content/plugins/event-calendar/eventcalendar3.php=>For ajax process page.
ec3_filter_query_vars_xml=>root/wp-content/plugins/event-calendar/eventcalendar3.php=>For ajax process page.

wp_widget_text()=>root/wp-includes/widgets.php=>For Get widget Text
wp_widget_rss()=>root/wp-includes/widgets.php=>For Get widget RSS
wp_widget_recent_comments()=>root/wp-includes/widgets.php=>For Get Comment

M:\wp-content\themes\default\archive.php =>For displaying article from archive.
M:\wp-content\themes\default\archive.php =>For displaying article from Category.
M:\wp-content\themes\default\archive.php =>For displaying article from Calender.

For Customize Calender Template

To Change Calnder year month display=>Go to ec3.js Line Number 121.

Recent Post =>single.php
Blog Archive=>archive.php
Calender Archive=>archive.php
Category Archive=>archive.php

have_posts()=>The have_posts function checks to see if the current post number is less than the number of posts you choose to display in the Admin panel. The loop will then continue until the current post number reachers the maximum number of posts you have decided to show.

the_author()=>Retrieves the author’s name.
the_title()=> Displays the title of the current post.
the_content()=> Displays the contents of the post.
the_permalink()=> Displays the URL for the post in the form of a permalink.
the_ID()=>Displays the post ID.

Global variable authordata can be used in a function using this code:

global $authordata;
echo $authordata->display_name;

The authordata global can also access: nickname, last_name, first_name, ID, user_email, user_url, user_login, description, and several others.

Global variable post can be used in a function using this code:

global $post;
echo $post->post_title;

The post global can also access: ID, post_author, post_date, post_excerpt, comment_count, and several others.


Follow

Get every new post delivered to your Inbox.