Flicker Images

Find programmers and grapic design experts at ScriptLance.com

Tuesday, December 27, 2011

How get tag name in Jquery



For finding any element tag name, we can get using following code.
Code
var tagName = $(this).get(0).tagName;

Example
<html>
<head>
<link href='css/custom-theme/jquery-ui-1.8.16.custom.css' rel='stylesheet' type='text/css'> 
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script>
</head>
<script>
$("#new_button").button();
$("#new_button").click(function() {
var TagName = $(this).get(0).tagName; 
alert(TagName);
var ParentTagName = $(this).parent().get(0).tagName; 
alert(ParentTagName);
});
</script>

<body>
<div style="display: table-cell; float: right;"><a id="new_button">New</a></div>
</body>
</html>
iPhone_Case_Bear_3468x60banner
Share:

Wednesday, December 21, 2011

SEO Question for Clients


  1.   What is the web address/URL of the site that you would like us to optimize? If your web address doesn´t up and running, please provide us your DEV URL or sitemap structure that you have planned.
  2.  In which platform your website built in?
  3. Describe the type of customers/audiences/visitors that you are targeting with your website.
  4. What are the products or services that you provide? Please provide us with a detailed description about the services that you offer
  5. What are your target specific keywords? Do you know what your customers to be will type in the search engine to find you?
    1.  What are the primary keywords you would like to target? (No single phrase keywords please)
    2.  What are the secondary level keywords you would like to target? (No single phrase keywords please)
    3.  Can we review the keywords and make changes as per your business objective?
  6. Who are your customers? Who are your best customers? And Why?
  7.  Who are your major competitors online? Do you know them how they perform online? List your major competitors with Name, Location and Website Addresses.(URL)
  8. What is the geographic scope of your market- International /National/ Regional/Local?
  9.  Do you have web stats (statistics) for your current site and monitoring the visitor status regularly?
  10.  Will you be interested in site restructuring, minor redesigns and content change if we strongly recommend? Promoting a client’s website is promoting their business. So, understanding their business is more important, and getting an insight about what they do, should be the first step you should do. Keep this in mind if you want to help them and retain them, since SEO clients are long term clients, and they rely on your marketing abilities.
  11.  How do you currently promote new content (Twitter, Facebook, LinkedIn, etc.)
  12. Define your current marketing strategy?
  13.  Do you have traffic stats / website log for us to review?If so, Can we have the access for the same?
  14. What do you want to accomplish with SEO/SEM? (Ranking / Traffic / Conversion )
  15. Have you worked with any SEO /SEM companies before? If so, what was performed and what were the results?
  16.  Do you have an established budget for SEO/SEM? If so, what is it?
  17.  Do you have any constraints while working the project (Timing / Budget etc)
  18.  Please provide any additional information you think might be essential at this time.

Note :
I collect this information from different website and Blogs and put it together.

Share:

Tuesday, November 22, 2011

Deleting Duplicate data from MySQL database in PHP

I am making an application from data import from excel file. In application user may be import several time or different file may be contains same data. But I always need unique data row from other calculation. So I badly need delete Duplicated row from table after importing data from excel file.
For Solve this problem I found couple of solution on web.

Solution 1: If table contain a primary key
Table :

 
  create table TableName1 (
  ID int(11) NOT NULL AUTO_INCREMENT ,
  CODE varchar(20) , 
  NAME varchar(100) ,
  PRIMARY KEY (ID)
  ) 
  
Data
ID CODE NAME
1 A1001 Mahfuz
2 A1002 Lemon
3 A1001 Mahfuz
4 A1002 Lemon
5 A1003 Babu


 <?php
 $conn = mysql_connect("localhost", "mysql_user", "mysql_password");
if (!$conn) {
    echo "Unable to connect to DB: " . mysql_error();
    exit;
}
if (!mysql_select_db("mydbname")) {
    echo "Unable to select mydbname: " . mysql_error();
    exit;
}



$sql = "DELETE FROM TableName1
USING TableName1, TableName1 AS vtable
WHERE vtable.id > TableName1.id
AND TableName1.CODE = vtable.CODE
And TableName1.NAME = vtable.NAME";

mysql_query($sql);

$sql_check = "SELECT NAME,
COUNT(NAME) AS NumOccurrences
FROM TableName1
GROUP BY NAME
HAVING ( COUNT(NAME) > 1 )";
$result = mysql_query($sql_check);

if (mysql_num_rows($result) == 0) {
    echo "No Duplicate rows found";
}
?>

Solution 2: If table have no primary key
Table :

 create table TableName1 ( 
  CODE varchar(20) , 
  NAME varchar(100)
)
Data
CODE NAME
A1001 Mahfuz
A1002 Lemon
A1001 Mahfuz
A1002 Lemon
A1003 Babu


 <?php

$conn = mysql_connect("localhost", "mysql_user", "mysql_password");
if (!$conn) {
    echo "Unable to connect to DB: " . mysql_error();
    exit;
}
if (!mysql_select_db("mydbname")) {
    echo "Unable to select mydbname: " . mysql_error();
    exit;
}



$sql1 = " CREATE TEMPORARY TABLE temp_TableName1 as select * from TableName1 group By code,name";

mysql_query($sql1);

$sql2 = " TRUNCATE TABLE TableName1 ";

mysql_query($sql2);

$sql3 = " INSERT INTO TableName1 SELECT * FROM temp_TableName1 ";

mysql_query($sql3);

$sql_check = "SELECT NAME,
COUNT(NAME) AS NumOccurrences
FROM TableName1
GROUP BY NAME
HAVING ( COUNT(NAME) > 1 )";
$result = mysql_query($sql_check);

if (mysql_num_rows($result) == 0) {
    echo "No Duplicate rows found";
}

?>
Share:

Sunday, November 20, 2011

what is difference between mysql_fetch_assoc, mysql_fetch_row,mysql_fetch_object and mysql_fetch_array


Definition :

  • mysql_fetch_array():-

    Fetch a result row as an associative array, a numeric array, or both by default it fetches both.
Returns an array of strings that corresponds to the fetched row, or FALSE  if there are no more rows. The type of returned array depends on how result_typeis defined. By using MYSQL_BOTH (default), you'll get an array with both associative and number indices. Using MYSQL_ASSOC, you only get associative indices (as mysql_fetch_assoc() works), using MYSQL_NUM, you only get number indices (as mysql_fetch_row() works).
  • mysql_fetch_row() :-

    Get a result row as an numeric array
Returns an numerical array of strings that corresponds to the fetched row, or FALSE if there are no more rows.
mysql_fetch_row() fetches one row of data from the result associated with the specified result identifier. The row is returned as an array.
  • mysql_fetch_object :-

    Fetch a result row as an object
Returns an object with string properties that correspond to the fetched row, orFALSE;if there are no more rows.
  • mysql_fetch_assoc() :-

    Fetch a result row as an associative array
Returns an associative array that corresponds to the fetched row and moves the internal data pointer ahead. mysql_fetch_assoc() is equivalent to callingmysql_fetch_array() with MYSQL_ASSOC for the optional second parameter. It only returns an associative array.

Example:

<?php

$conn = mysql_connect("localhost", "mysql_user", "mysql_password");

if (!$conn) {
    echo "Unable to connect to DB: " . mysql_error();
    exit;
}
  
if (!mysql_select_db("mydbname")) {
    echo "Unable to select mydbname: " . mysql_error();
    exit;
}

$sql = "SELECT id as userid, fullname, userstatus 
        FROM   sometable
        WHERE  userstatus = 1";

$result = mysql_query($sql);

if (!$result) {
    echo "Could not successfully run query ($sql) from DB: " . mysql_error();
    exit;
}

if (mysql_num_rows($result) == 0) {
    echo "No rows found, nothing to print so am exiting";
    exit;
}

// While a row of data exists, put that row in $row as an associative array
// Note: If you're expecting just one row, no need to use a loop
// Note: If you put extract($row); inside the following loop, you'll
//       then create $userid, $fullname, and $userstatus
while ($row = mysql_fetch_array ($result)) {
    echo $row[0];
    echo $row[1];
    echo $row[2];
}

while ($row = mysql_fetch_array ($result)) {
    echo $row["userid"];
    echo $row["fullname"];
    echo $row["userstatus"];
}

while ($row = mysql_fetch_array ($result)) {
    echo $row[0];
    echo $row["fullname"];
    echo $row[2];
}

while ($row = mysql_fetch_row($result)) {
    echo $row[0];
    echo $row[1];
    echo $row[2];
}

while ($row = mysql_fetch_object($result)) {
    echo $row->userid;
    echo $row->fullname;
    echo $row->userstatus;
}

while ($row = mysql_fetch_assoc($result)) {
    echo $row["userid"];
    echo $row["fullname"];
    echo $row["userstatus"];
}


mysql_free_result($result);
?>


Performance
Using both  mysql_fetch_array() and mysql_fetch_assoc()  is not significantly slower than using mysql_fetch_row(),
Speed-wise, the function is identical to mysql_fetch_array(), and almost as quick as mysql_fetch_row() (the difference is insignificant).
mysql_fetch_object() is similar to mysql_fetch_array(), with one difference - an object is returned, instead of an array. Indirectly, that means that you can only access the data by the field names, and not by their offsets (numbers are illegal property names).
Share:

Thursday, November 17, 2011

How to create a 'Close page' message for unsaved web form data?




I'm creating an PHP web application and I want to implement logic to warn the user when they are navigating away from a page they've edited. I found some solution on the .


For this solution we bound a JavaScript function to the unload event:
 window.onbeforeunload  

I use following code in different aspect
For all type of Input .


$(document).ready(function() { 
    $(":input").one("change", function() { 
        window.onbeforeunload = function() { return 'You will lose data changes.'; } 
    }); 
    $('.noWarn').click(function() { window.onbeforeunload = null; }); 
});

Your input elements probably do not exist when the code is executed. Try using the .live function to detect changes on all input elements, or wrap your code in a $(document).ready() handler.

$('input').live("change", function () {
    window.onbeforeunload = function () { return "Your changes have not been saved?" };
});

For specific input type on body

$(document).ready(function() {

    //----------------------------------------------------------------------
    // Don't allow us to navigate away from a page on which we're changed
    //  values on any control without a warning message.  Need to class our 
    //  save buttons, links, etc so they can do a save without the message - 
    //  ie. CssClass="noWarn"
    //----------------------------------------------------------------------
    $('input:text,input:checkbox,input:radio,textarea,select').one('change', function() {
        $('BODY').attr('onbeforeunload',
        "return 'Leaving this page will cause any unsaved data to be lost.';");
    });

    $('.noWarn').click(function() { $('BODY').removeAttr('onbeforeunload'); });

});

Best solution for form base: In this solution if you are change something in your form then when you want to leave from this page user can get a message for confirmation.

function formIsDirty(form)
      {
          for (var i = 0; i < form.elements.length; i++)
          {
              var element = form.elements[i];
              var type = element.type;
              if (type == "checkbox" || type == "radio")
              {
                  if (element.checked != element.defaultChecked)
                  {
                      return true;
                  }
              }
              else if (type == "hidden" || type == "password" || type == "text" ||
                       type == "textarea")
              {
                  if (element.value != element.defaultValue)
                  {
                      return true;
                  }
              }
              else if (type == "select-one" || type == "select-multiple")
              {
                  for (var j = 0; j < element.options.length; j++)
                  {
                      if (element.options[j].selected !=
                          element.options[j].defaultSelected)
                      {
                          return true;
                      }
                  }
              }
          }
          return false;
      }

      window.onbeforeunload = function(e)
      {
          e = e || window.event;  
// You put your from ID
          if (formIsDirty(document.forms['fromid'])) 
          {
              // For IE and Firefox
              if (e)
              {
                  e.returnValue = "You have unsaved changes.";
              }
              // For Safari
              return "You have unsaved changes.";
          }
      };

Share:

Wednesday, November 16, 2011

how we get current date ,month and year( C#.net)



You can get Current day, month, and year using this class


public class MY_Date
{
    /// <summary>
    /// Current Month
    /// </summary>
    public static string CurMonth = GetCurrentMonth();
        /// <summary>
        /// Current Year
        /// </summary>
        public static string CurYear =GetCurrentYear();

    /// Current Month
    /// </summary>
    public static DateTime Yesterday = GetYesterday();
        /// <summary>
        /// Current Year
        /// </summary>
    public static DateTime Tomorrow = GetTomorrow();
     
private static string GetCurrentYear()
{
DateTime dt = DateTime.Now;
            return dt.Year.ToString();
        }
private static string GetCurrentMonth()
{
DateTime dt = DateTime.Now;
            return dt.Month.ToString();
        }
/// <summary>
        /// last day of the year for today.
        /// </summary>
        static DateTime LastDayOfYear()
        {
   return LastDayOfYear(DateTime.Today);
        }

        /// <summary>
        /// last day of the year for the selected day's year.
        /// </summary>
        static DateTime LastDayOfYear(DateTime d)
        {
   // 1
   // Get first of next year
   DateTime n = new DateTime(d.Year + 1, 1, 1);
   // 2
   // Subtract 1 from it
   return n.AddDays(-1);
        }
    /// <summary>
        /// Gets the first day of the current year.
        /// </summary>
        static DateTime FirstDayOfYear()
        {
   return FirstDayOfYear(DateTime.Today);
        }

        /// <summary>
        /// Finds the first day of year of the specified day.
        /// </summary>
        static DateTime FirstDayOfYear(DateTime y)
        {
   return new DateTime(y.Year, 1, 1);
        }
   
    /// <summary>
        /// Gets the next day, tomorrow.
        /// </summary>
        private static DateTime GetTomorrow()
        {
   return DateTime.Today.AddDays(1);
        }
   /// <summary>
        /// Gets the previous day to the current day.
        /// </summary>
        private static DateTime GetYesterday()
        {
   // Add -1 to now
   return DateTime.Today.AddDays(-1);
        }

}
Share:

Monday, April 18, 2011

Setting up an Oracle / PHP connection



Require Software:
Oracle 10g Express edition:

PHP
Apache

Or

Wampserver

Or

XAMAP



This time I am using Wampserver 2i.  For avoiding hassle installing apache and PHP install separately.
You can install apache and PHP separately.

Now describe step by step:

Step 1: Install wampserver .
Step 2: Install Oracle 10g express edition.
Step 3:
The OCI8 and PDO_OCI extensions are included in PHP.
The basic steps to configure OCI8 are:

  •    Open  your php.ini file
  •    Search OCI8 in php.ini file

  •         Default it’s commented so you need to uncomment it.


Step 4:  Now check your oracle client. 
Step 5:  create a sample php file “test.php”
<?php

echo "hello world";

$conn = oci_connect('myusername', 'password', 'host/xe');

do_query($conn, 'SELECT * FROM TAB1);
// Execute query and display results
function do_query($conn, $query)
{
$stid = oci_parse($conn, $query);
$r = oci_execute($stid, OCI_DEFAULT);
print '<table border="1">';
while ($row = oci_fetch_array($stid, OCI_RETURN_NULLS)) {
print '<tr>';
foreach ($row as $item) {


 echo "  <td>".($item !== null ? htmlentities($item, ENT_QUOTES) : "&nbsp;")."</td>\n";
}
print '</tr>';
}
print '</table>';
}

?>

Step 6: Now run you server and open that “test.php”
Share:

Friday, March 11, 2011


Microsoft SQL Server 2005 Database Encryption Step-by-Step
This is a how-to guide which will aims to help ms sql server developers and ms sql server administrators to implement Microsoft SQL Server 2005 Encryption methodologies.
This tutorial is a step-by-step guide for encryption and decryption in MS SQL Server 2005 and later (MS SQL2008 aka Katmai)
Creating Master Key
Before using encryption algoritms in SQL Server 2005 and SQL Server 2008, a master key should be created in the database where encryption is going to be used.
Note that master key is created seperately for each database on a SQL Server database instance
Before creating a master key, sql developers or sql server database administers that has the required permissions can run the below t-sql select query to see if a master key is created before.
SELECT * FROM sys.symmetric_keys


If there has been created a master key, you
will see a result that is similar to below if you are running the t-sql select from sys.symmetric_keys view in MS SQL Server 2005,

Note that in SQL2008 (CTP6 or February CTP) sys.symmetric_keys view has additional columns:
name
principal_id
symmetric_key_id
key_length
key_algorithm
algorithm_desc
create_date
modify_date
key_guid
key_thumbprint
provider_type
cryptographic_provider_guid
cryptographic_provider_algid
It is important that for a database in MS SQL Server, there can be only one master key in other words a single master key can be created on a database. A second master key can not be created in a sql server database.
You can use the below t-sql script code in order to create a master key in the sql database.
/*************** CREATE MASTER KEY *********************************/
IF NOT EXISTS (
SELECT * FROM sys.symmetric_keys WHERE name = N'##MS_DatabaseMasterKey##'
)
CREATE MASTER KEY ENCRYPTION BY PASSWORD = '$EncryptionPassword12'
GO
It is important that you keep the encryption password in a safe place or keep backups of your sql server database master key.
I'm going to deal with master key backup later in this tutorial.
You can drop or remove an existing master key using the
DROP MASTER KEY t-sql command.
If you try to drop a master key which has been used for creating other database objects like certificates the DROP MASTER KEY sql command will fail.
If you run the DROP MASTER KEY sql server statement after a certificate is defined which we will see in the next step, the following error message is going to be informing the sql server programmer about the dependent certificate.
Msg 15580, Level 16, State 1, Line 2
Cannot drop master key because certificate 'PasswordFieldCertificate' is encrypted by it.
Creating a Certificate
The second step for using encryption in a SQL Server database is creating the certificates that will be used for creating symmetric keys and encrypting database table column fields.
So creating a certificate is still a preparation step in the encryption process.
Encrypting table column values or sql variables is still a few steps ahead.
You can also view existing certificates in a MS SQL Server database by running a select query over
sys.certificates view.
SELECT * FROM sys.certificates

You can run the below t-sql script to create a certificate.
/*************** CREATE CERTIFICATE *********************************/
IF NOT EXISTS (
SELECT * FROM sys.certificates WHERE name = N'PasswordFieldCertificate'
)
CREATE CERTIFICATE PasswordFieldCertificate WITH SUBJECT = 'Password Fields';
GO
You can also drop or remove an existing certificate from a database using the DROP CERTIFICATE certificate_name tsql syntax.
If you try to drop a certificate that is used during the creation of a symmetric key, etc. the following error message is going to be thrown by the SQL Server engine.
Msg 15352, Level 16, State 1, Line 2
The certificate cannot be dropped because one or more entities are either signed or encrypted using it.
Creating a Symmetric Key
After the certifates are created in the sql database, next the symmetric key is being generated by executing a CREATE SYMMETRIC KEY SQL Server command.
Again, you can check
sys.symmetric_keys view name fields whether a key already exists and declared in the current database.
The following sql code script is enough to create a symmetric key which will be used for encryption and for decryption in the sql database.
/*************** CREATE SYMMETRIC KEY *********************************/
CREATE SYMMETRIC KEY PasswordFieldSymmetricKey
WITH ALGORITHM = AES_256
ENCRYPTION BY CERTIFICATE PasswordFieldCertificate;

If you try to create symmetric key with a name that exists among the sys.symmetric_keyssystem view, the following error message will be displayed:
Msg 15282, Level 16, State 1, Line 1
A key with name 'PasswordFieldSymmetricKey' or user defined unique identifier already exists or you do not have permissions to create it.
In the above CREATE SYMMETRIC KEY t-sql statement one important point is the algorithm parameter that is specified in the command.
Microsoft SQL Server can use the following algorithms in encryption sensitive data.
DES, TRIPLE_DES, RC2, RC4, RC4_128, DESX, AES_128, AES_192 and AES_256
As system administrators or database admins, one important note for AES_128, AES_192 and AES_256 is AES encryption algorithm can not be used on Microsoft Windows 2000 Servers and Windows XP operating systems. If you have a MS SQL Server instance running on a Win2k server, then it is better to create the symmetric keys using the TRIPLE_DES algorithm, for instance. Otherwise, your script will fail when it is run on a sql server which is installed on Windows 2000 servers and Windows XP computers since AES is not supported on those operating systems. You should consider this point while choosing an encryption algorithm for your SQL Server database applications.
Preparing Database Tables to Store Encrypted Data
Now it is time to create a table column field which will store or keep the encrypted values in it for us.
Since I'm working on AdventureWorks database which I have downloaded and installed as a sample database for MS SQL Server 2008 CTP 6, I'll try to alter a table in AdventureWorks db and add a new column for storing encrypted data.
Since password fields is not open or visible in Person.Contact table, I give up searching for a password field in any of tables in AdventureWorks. I want to encrypt EmailAddress data column values in Person.Contact table.
I'm adding a table column named EncryptedEmailAddress which is declared as varbinary data type and 256 bytes in length using the below ALTER TABLE sql command.
If this varbinary field is not enough in length or size to store the resultant encrypted data, the encryption sql commands will generate an error.
ALTER TABLE Person.Contact
ADD EncryptedEmailAddress varbinary(256);
GO
Now run the below select query and observe that the Encrypted e-mail address column is null. We have not updated this encrypted field yet.
SELECT EmailAddress, EncryptedEmailAddress FROM Person.Contact
Encrypting Sensitive Data
Here is the final step for encrypting a table field using MS SQL Server encryption algoritms and methods.
An encryption can be done on a string or binary value (in nvarchar, varchar, varbinary, nchar, char, binary sql data types) in SQL Server using the
EncryptByKey t-sql function.
EncryptByKey
encrypts a given data by using a symmetric key.
The necessary symmetric key information can be passed to the EncryptByKey function using the
Key_GUID Transact-SQL function. Key_GUID returns the uniqueidentifier (GUID) of the symmetric key whose key name is specified in the Key_GUID function.
The output of the encryption function EncryptByKey is a varbinary with a maximum lenth 8000 bytes.
Since EncryptByKey t-sql command requires a symmetric key, if you execute the EncryptByKey command without openning the symmetric key, the EncryptByKey function will return NULL values during the encrypting calls.
Once the symmetric key is opened in a session, EncryptByKey will function properly in that session. This means as a sql server developer after opening the symmetric key in a session, you can then call the encryption and also the decryption functions more than once successfully.
Also, if you plan to encrypt data and write it on a table or store encrypted data in a stored procedure or in a user defined function (udf), you can open the related symmetric key once at the beginning of the stored procedure or user-defined function t-sql codes, and then in the following lines of sql codes you can execute the EncryptByKey and the DecryptByKey Transact-SQL commands.
/*************** ENCRYPT SENSITIVE DATA *********************************/
OPEN SYMMETRIC KEY PasswordFieldSymmetricKey
DECRYPTION BY CERTIFICATE PasswordFieldCertificate;
UPDATE Person.Contact SET EncryptedEmailAddress = EncryptByKey(Key_GUID('PasswordFieldSymmetricKey'), EmailAddress);
SELECT EmailAddress, EncryptedEmailAddress FROM Person.Contact
GO
Decrypting Encrypted Data
Of course, if you are encrypting your data in Microsoft SQL Server 2005 or the new version SQL2008 aka Katmai, you may also want to decrypt the encrypted data.
As well as encrypting, decrypting can be handled using t-sql commands and functions in SQL Server.
DecryptByKey t-sql function decrypts data using a symmetric key definen in the current sql database.
You can call the DecryptByKey function passing the encrypted data in varbinary data type. Just as similar to EncryptByKey requires an opened symmetric key in the current session, DecryptByKey function also requires a symmetric key that has been opened in the current session before it is called.
Therefore, the t-sql codes below are executed before making any call to EncryptByKey or DecryptByKey t-sql functions.
OPEN SYMMETRIC KEY PasswordFieldSymmetricKey
DECRYPTION BY CERTIFICATE PasswordFieldCertificate;
/*************** DECRYPT *********************************/
OPEN SYMMETRIC KEY PasswordFieldSymmetricKey
DECRYPTION BY CERTIFICATE PasswordFieldCertificate;
SELECT
EmailAddress,
EncryptedEmailAddress,
CONVERT(nvarchar, DecryptByKey(EncryptedEmailAddress)) AS 'Decrypted Email Address'
FROM Person.Contact;
GO

One last important point for decrypting encrypted data on SQL Server is that as a sql programmer or administrator, you should take care for the original data type that is encrypted and the target data type that the decrypted data is going to be converted.
Since DecryptByKey function returns data in
varbinary data type up to 8000 bytes, if you convert this decrypted varbinary data to nvarchar sql data type you get different result when compared to decrypted varbinary data converted to varchar.
So, if you are encrypting nvarchar data, decrypt and convert it back to nvarchar. Same for varchar data type also. if you are encrypting varchar data, decrypt and convert it back to varchar. Otherwise, you will not get expected results from implemented decryption algorithm.
Let's look at the following select script where encryption and decryption takes place for both varchar and nvarchar data types.
You will see if nvarchar data is converted back to nvarchar then result is correct. Same is true for also varchar data.
SELECT
-- Encrypt 'Varchar' string and then decrypt encrypted data
CONVERT(varchar, DecryptByKey(EncryptByKey(Key_GUID('PasswordFieldSymmetricKey'), 'Varchar'))),
CONVERT(nvarchar, DecryptByKey(EncryptByKey(Key_GUID('PasswordFieldSymmetricKey'), 'Varchar'))),
-- Encrypt N'NVarchar' string and then decrypt encrypted data
CONVERT(varchar, DecryptByKey(EncryptByKey(Key_GUID('PasswordFieldSymmetricKey'), N'NVarchar'))),
CONVERT(nvarchar, DecryptByKey(EncryptByKey(Key_GUID('PasswordFieldSymmetricKey'), N'NVarchar')))

Using Parameters in EncryptByKey and DecryptByKey T-SQL Functions
I have used string values or database table column names in the previous examples. But sql variables can also be used for encryption and decryption functions.
DECLARE @sample_data nvarchar(MAX)
SET @sample_data = N'This is a step-by-step guide summarizing SQL Server Encryption'
SELECT
CONVERT(nvarchar(MAX), DecryptByKey(EncryptByKey(Key_GUID('PasswordFieldSymmetricKey'), @sample_data)))

In this step-by-step guide or SQL Server encryption and decryption tutorial, we have implemented SQL Server data encryption and encryption metodologies with sample t-sql codes in a simple application in Microsoft SQL Server 2005 and MS SQL Server 2008. Encryption and Decryption is an important aspect for database security in sql database development
Share:

Game Reviews

BTemplates.com

Powered by Blogger.

Search This Blog

Video Of Day

Find Us OIn Facebook

Blogroll

Contact

Tackle the Web with up to 5 new .COMs, $5.99 for the 1st year!

Advertisement