Tuesday, August 31, 2010

C# Insert

public static void InsertCustomer(string FName,string LName,string Email,string Location)
{
string sqlConnString = null;

// Get connection string
sqlConnString = ConfigurationSettings.AppSettings["dbConn"].ToString();

using (SqlConnection sqlConn = new SqlConnection(sqlConnString))
{
try
{
//Create command.
SqlCommand command = new SqlCommand("usp_InsCustomer", sqlConn);
command.CommandType = CommandType.StoredProcedure;
command.CommandTimeout = 30;

//Build parameter list.
command.Parameters.Add(new SqlParameter("@FName", SqlDbType.NVarChar, 256));
command.Parameters.Add(new SqlParameter("@LName", SqlDbType.NVarChar, 256));
command.Parameters.Add(new SqlParameter("@Email", SqlDbType.NVarChar, 256));
command.Parameters.Add(new SqlParameter("@Location", SqlDbType.NVarChar, 256));
//command.Parameters.Add(new SqlParameter("@IPAddress", SqlDbType.NVarChar, 256));

//Add values for the parameters.
command.Parameters[0].Value = FName;
command.Parameters[1].Value = LName;
command.Parameters[2].Value = Email;
command.Parameters[3].Value = Location;
command.Parameters[4].Value = NumberOfHugs;
//command.Parameters[5].Value = IPAddress;

//Open Connection
sqlConn.Open();

//Fire Command
command.ExecuteNonQuery();

}
catch (Exception ex)
{
//Eat exception
}
}

}

Database Differential Backup Restore

USE master

restore database [DBName]
from disk = 'D:\SQL2005\Backups\Temporary Backups\User DB Backups\FullBackup\DBBackupFolder\DB_backup.bak'
with move 'DBDataFile' to 'D:\SQL2005\Data\DBDataFile.mdf',
move 'DBLogFile' to 'D:\SQL2005\Data\DBLogFile_log.ldf',
norecovery, Replace

--now the diff backup
restore database [PMPoint_0624]
from disk = ' D:\SQL2005\Backups\Temporary Backups\User DB Backups\FullBackup\DBBackupFolder\DB_Restore_backup.bak'
with move ''DBDataFile' to 'D:\SQL2005\Data\DBDataFile.mdf',
move 'DBLogFile' to 'D:\SQL2005\Data\DBLogFile_log.ldf',
recovery