Have a fun while searching

Tuesday, July 5, 2011

Get Ip Address using 3rd part web service

script language="JavaScript" src="http://www.ipaddresslocation.org/my-ip-address.php"
type="text/JavaScript"

Multiple Codes

http://www.xpode.com/

Encription and Decription

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;
using System.Xml;
using System.Security.Cryptography;
using System.Net.Mail;
using System.Data.SqlClient;
namespace EncryptBF
{
public class Encry
{
public string encryptPassword(string strText)
{
return Encrypt(strText, "&%#@?,:*");
}
public string decryptPassword(string str)
{
return Decrypt(str, "&%#@?,:*");
}
private string Encrypt(string strText, string strEncrypt)
{

byte[] byKey = new byte[20];

byte[] dv = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };

try
{

byKey = System.Text.Encoding.UTF8.GetBytes(strEncrypt.Substring(0, 8));

DESCryptoServiceProvider des = new DESCryptoServiceProvider();

byte[] inputArray = System.Text.Encoding.UTF8.GetBytes(strText);

MemoryStream ms = new MemoryStream();

CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(byKey, dv), CryptoStreamMode.Write);

cs.Write(inputArray, 0, inputArray.Length);

cs.FlushFinalBlock();

return Convert.ToBase64String(ms.ToArray());

}

catch (Exception ex)
{

throw ex;

}

}



private string Decrypt(string strText, string strEncrypt)
{

byte[] bKey = new byte[20];

byte[] IV = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };

try
{

bKey = System.Text.Encoding.UTF8.GetBytes(strEncrypt.Substring(0, 8));

DESCryptoServiceProvider des = new DESCryptoServiceProvider();

Byte[] inputByteArray = inputByteArray = Convert.FromBase64String(strText);

MemoryStream ms = new MemoryStream();

CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(bKey, IV), CryptoStreamMode.Write);

cs.Write(inputByteArray, 0, inputByteArray.Length);

cs.FlushFinalBlock();

System.Text.Encoding encoding = System.Text.Encoding.UTF8;

return encoding.GetString(ms.ToArray());

}

catch (Exception ex)
{

throw ex;

}

}

private String GeneratePasskey()
{
int stringLength = 10;

Random rnd = new Random((int)System.DateTime.Now.Ticks);
System.Text.StringBuilder randomText = new
System.Text.StringBuilder(stringLength);

//value of A in ascii codes
int minValue = 65;

//value of Z in ascii codes
int maxValue = 90;

//the range that we are allowed to go above the min value
int randomRange = maxValue - minValue;

double rndValue;

for (int i = 0; i < stringLength; i++)
{
rndValue = rnd.NextDouble();

randomText.Append((char)(minValue + rndValue * randomRange));
}


return randomText.ToString().ToLower();
}

private String GetReferenceNumber()
{
int size = 10;

Random r = new Random();

string legalChars = "123456789abcdefghijklmnopqrstuvwxyz";

StringBuilder sb = new StringBuilder();

for (int i = 0; i < size; i++)

sb.Append(legalChars.Substring(r.Next(0, legalChars.Length - 1), 1));

return sb.ToString();
}
}
}

Book Mark Using java script

----------javascript--------------------

function bookmarksite(title, url) {

if (window.sidebar) // firefox
window.sidebar.addPanel(title, url, "");
else if (window.opera && window.print) { // If browser is opera
var elem = document.createElement('a');
elem.setAttribute('href', url);

elem.setAttribute('title', title);
elem.setAttribute('rel', 'sidebar');
elem.click();
}


else if (document.all)// If browser is ie

window.external.AddFavorite(url, title);

}


----------Link------------------------
a href="javascript:bookmarksite(location.href, location.href)"

Backup and Restore and Split File Backup

1) Conventional and Split File Backup and Restore
BACKUP DATABASE demo
TO DISK = 'C:\demo1.bak',
DISK = 'C:\demo2.bak',
DISK = 'C:\demo3.bak'
GO

RESTORE DATABASE weather
FROM DISK = 'C:\demo1.bak',
DISK = 'C:\demo2.bak',
DISK = 'C:\demo3.bak'
GO

2) Mirror Backup of the file:-
It is quite a common practice to create an exact copy of the backup and store it to several places to deal with any catastrophes which might affect the place where the database is stored. Once a full backup is accomplished DBAs generally copy the database to another location in their network using a third party tools like robocopy or native DOS commands like xcopy.

In SQL Server 2005 and later versions, there is a Mirror command that makes a copy of the database backup to different locations while taking the original backup. The maximum limit of additional locations that can be specified with MIRROR clause is 3.

Mirrored backup can be taken in local computer system as well as in a local network. Let us now see two examples of mirror backup.

Example 1. Single File Backup to Multiple Locations using Mirror
BACKUP DATABASE AdventureWorks
TO DISK = 'C:\Backup\SingleFile\AdventureWorks.bak'
MIRROR TO DISK = 'C:\Backup\MirrorFile\AdventureWorks.bak'
WITH FORMAT
GO
If this command is being run for the first time, it is mandatory to use the WITH FORMAT clause; but for sub sequential runs it is not required. WITH FORMAT reinitializes the backup.

When checked in both the folders ‘SingleFile’ and ‘MirrorFile’, backup files are exactly the same files. As mentioned earlier, four mirror backup can be specified in total.

Example 2. Split File Backup to Multiple Locations using Mirror
We have earlier seen an example where we can have multiple split files of large database backup files. SQL Server Mirror functionality also supports backup of the split files.

BACKUP DATABASE AdventureWorks
TO DISK = 'C:\Backup\MultiFile\AdventureWorks1.bak',
DISK = 'C:\Backup\MultiFile\AdventureWorks2.bak',
DISK = 'C:\Backup\MultiFile\AdventureWorks3.bak'
MIRROR TO DISK = 'C:\Backup\MirrorFile\AdventureWorks1.bak',
DISK = 'C:\Backup\MirrorFile\AdventureWorks2.bak',
DISK = 'C:\Backup\MirrorFile\AdventureWorks3.bak'
WITH FORMAT
GO

All the mirror sets will need the same number of DISK clauses as the original backup media.

Mirrored database backup can be restored using the same method as the original backup. Mirrored backup is in fact an exact replica of the original backup.

Understanding the FORMAT Clause
The FORMAT clause is used to reinitiate a backup media. Although it is a very useful clause it should be used with caution. When the clause is used it erases everything present in backup media. I have noticed that some DBAs are confused while taking a backup on a local disk where they have SQL Server installed. They have a misconception that if the format command is used, it will erase the complete disk including the SQL Server installation. However, the fact is that SQL Server format clause is quite different from OS format. The effect of SQL Server format clause is limited to a folder or path specified in the DISK clause.

In our example, when the FORMAT clause is specified, it will format only folders like C:\Backup\MultiFile\ or C:\Backup\SingleFile.

Related Errors
Error 3010
Invalid backup mirror specification. All mirrors must have the same number of members.

This error can show up while taking a mirrored database backup along with a regular backup; and DISK and MIRROR TO DISK do not match accurately.

The following image demonstrates how the error takes place.



To fix the error, match the members of DISK and MIRROR TO DISK to each other.



Error 3215
Use WITH FORMAT to create a new mirrored backup set

This error can spring up when a new backup is initiated and an existing media header needs to be reset for all headers on the backup media. If there is already a backup on the media, it will display this error and prevent backup from being overwritten. To fix this error, use WITH FORMAT as shown in an earlier example.

Miscellaneous details about Backup and Restore
When no options are specified, BACKUP DATABASE takes only full backups. Before taking the first log backup, full database backup is necessary to take one full backup. Backups created on later versions of SQL Server cannot be restored to earlier versions of SQL Server. The user needs permissions of sysadmin or db_owner or db_backupoperator roles to perform backup operation.


taken by:- http://dotnetslackers.com/articles/sql/Mirrored-Backup-and-Restore-and-Split-File-Backup.aspx

Thursday, May 26, 2011

check limit in datalist checkbox

----------------------script------------------------
script type="text/javascript"
// this is for the limit of how many checkboxes can be checked in datalist
function chkCount(obj) {
if (obj.checked == true) {
if (document.getElementById('gt;%=hiddenChkCount.ClientID %lt;').value >=2) {
alert('You cannot select more than 2 items.');
obj.checked = false;
}
else {
document.getElementById('gt;%=hiddenChkCount.ClientID %lt;').value = parseInt(document.getElementById('gt;%=hiddenChkCount.ClientID %lt;').value) + 1;
}
}
else {
document.getElementById('gt;%=hiddenChkCount.ClientID %lt;').value = parseInt(document.getElementById('gt;%=hiddenChkCount.ClientID %lt;').value) - 1;
}
}
/script
----------------------aspx page---------------------------------------

-------------------c#.net -----------------------------------
protected void dlShowWelcomeBooks_ItemDataBound(object sender, DataListItemEventArgs e)
{
CheckBox chk = default(CheckBox);
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
// get reference to checkbox control placed inside the first cell of gridview control
chk = (CheckBox)e.Item.FindControl("checkBooks");
// add onclick event to the checkbox to call javascript validation function
chk.Attributes.Add("onclick", "chkCount(this)");
}
}

Tuesday, May 3, 2011

Modify query string dynamicaly without effecting other

using System.Reflection;
using System.Collections.Specialized;
+++++++++++++++++++++++++++++++++++++++++++++++++++
//Modify the query string at run time
string path = HttpContext.Current.Request.Url.AbsoluteUri;
string[] strarr = path.Split('?');
if (strarr.Length > 1)
{
if (strarr[1].Contains("JobType"))
{
// reflect to readonly property
PropertyInfo isreadonly =

typeof(System.Collections.Specialized.NameValueCollection).

GetProperty("IsReadOnly", BindingFlags.Instance |

BindingFlags.NonPublic);

// make collection editable


isreadonly.SetValue(this.Request.QueryString, false, null);

// modify
this.Request.QueryString.Set("JobType",

Convert.ToString(e.CommandName));

// make collection readonly again


isreadonly.SetValue(this.Request.QueryString, true, null);

Response.Redirect(strarr[0] + "?" +

this.Request.QueryString, false);
}
else
{
Response.Redirect(path + "&JobType=" +

Convert.ToString(e.CommandName), false);
}
}
else
{
Response.Redirect(path + "?JobType=" +

Convert.ToString(e.CommandName), false);
}