Tuesday, January 1, 2019

How to transfer logins and passwords between SQL Server

Transfer logins and passwords to destination server (Server A) using scripts generated on source server (Server B)

To create a script on the source Server, follow these steps:

  1. On server A, start SQL Server Management Studio, and then connect to the instance of SQL Server from which you moved the database.
  2. Open a new Query Editor window, and then run the following script.
    USE master
    GO
    IF OBJECT_ID ('sp_hexadecimal') IS NOT NULL
      DROP PROCEDURE sp_hexadecimal
    GO
    CREATE PROCEDURE sp_hexadecimal
        @binvalue varbinary(256),
        @hexvalue varchar (514) OUTPUT
    AS
    DECLARE @charvalue varchar (514)
    DECLARE @i int
    DECLARE @length int
    DECLARE @hexstring char(16)
    SELECT @charvalue = '0x'
    SELECT @i = 1
    SELECT @length = DATALENGTH (@binvalue)
    SELECT @hexstring = '0123456789ABCDEF'
    WHILE (@i <= @length)
    BEGIN
      DECLARE @tempint int
      DECLARE @firstint int
      DECLARE @secondint int
      SELECT @tempint = CONVERT(int, SUBSTRING(@binvalue,@i,1))
      SELECT @firstint = FLOOR(@tempint/16)
      SELECT @secondint = @tempint - (@firstint*16)
      SELECT @charvalue = @charvalue +
        SUBSTRING(@hexstring, @firstint+1, 1) +
        SUBSTRING(@hexstring, @secondint+1, 1)
      SELECT @i = @i + 1
    END
    
    SELECT @hexvalue = @charvalue
    GO
     
    IF OBJECT_ID ('sp_help_revlogin') IS NOT NULL
      DROP PROCEDURE sp_help_revlogin
    GO
    CREATE PROCEDURE sp_help_revlogin @login_name sysname = NULL AS
    DECLARE @name sysname
    DECLARE @type varchar (1)
    DECLARE @hasaccess int
    DECLARE @denylogin int
    DECLARE @is_disabled int
    DECLARE @PWD_varbinary  varbinary (256)
    DECLARE @PWD_string  varchar (514)
    DECLARE @SID_varbinary varbinary (85)
    DECLARE @SID_string varchar (514)
    DECLARE @tmpstr  varchar (1024)
    DECLARE @is_policy_checked varchar (3)
    DECLARE @is_expiration_checked varchar (3)
    
    DECLARE @defaultdb sysname
     
    IF (@login_name IS NULL)
      DECLARE login_curs CURSOR FOR
    
          SELECT p.sid, p.name, p.type, p.is_disabled, p.default_database_name, l.hasaccess, l.denylogin FROM 
    sys.server_principals p LEFT JOIN sys.syslogins l
          ON ( l.name = p.name ) WHERE p.type IN ( 'S', 'G', 'U' ) AND p.name <> 'sa'
    ELSE
      DECLARE login_curs CURSOR FOR
    
    
          SELECT p.sid, p.name, p.type, p.is_disabled, p.default_database_name, l.hasaccess, l.denylogin FROM 
    sys.server_principals p LEFT JOIN sys.syslogins l
          ON ( l.name = p.name ) WHERE p.type IN ( 'S', 'G', 'U' ) AND p.name = @login_name
    OPEN login_curs
    
    FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @type, @is_disabled, @defaultdb, @hasaccess, @denylogin
    IF (@@fetch_status = -1)
    BEGIN
      PRINT 'No login(s) found.'
      CLOSE login_curs
      DEALLOCATE login_curs
      RETURN -1
    END
    SET @tmpstr = '/* sp_help_revlogin script '
    PRINT @tmpstr
    SET @tmpstr = '** Generated ' + CONVERT (varchar, GETDATE()) + ' on ' + @@SERVERNAME + ' */'
    PRINT @tmpstr
    PRINT ''
    WHILE (@@fetch_status <> -1)
    BEGIN
      IF (@@fetch_status <> -2)
      BEGIN
        PRINT ''
        SET @tmpstr = '-- Login: ' + @name
        PRINT @tmpstr
        IF (@type IN ( 'G', 'U'))
        BEGIN -- NT authenticated account/group
    
          SET @tmpstr = 'CREATE LOGIN ' + QUOTENAME( @name ) + ' FROM WINDOWS WITH DEFAULT_DATABASE = [' + @defaultdb + ']'
        END
        ELSE BEGIN -- SQL Server authentication
            -- obtain password and sid
                SET @PWD_varbinary = CAST( LOGINPROPERTY( @name, 'PasswordHash' ) AS varbinary (256) )
            EXEC sp_hexadecimal @PWD_varbinary, @PWD_string OUT
            EXEC sp_hexadecimal @SID_varbinary,@SID_string OUT
     
            -- obtain password policy state
            SELECT @is_policy_checked = CASE is_policy_checked WHEN 1 THEN 'ON' WHEN 0 THEN 'OFF' ELSE NULL END FROM sys.sql_logins WHERE name = @name
            SELECT @is_expiration_checked = CASE is_expiration_checked WHEN 1 THEN 'ON' WHEN 0 THEN 'OFF' ELSE NULL END FROM sys.sql_logins WHERE name = @name
     
                SET @tmpstr = 'CREATE LOGIN ' + QUOTENAME( @name ) + ' WITH PASSWORD = ' + @PWD_string + ' HASHED, SID = ' + @SID_string + ', DEFAULT_DATABASE = [' + @defaultdb + ']'
    
            IF ( @is_policy_checked IS NOT NULL )
            BEGIN
              SET @tmpstr = @tmpstr + ', CHECK_POLICY = ' + @is_policy_checked
            END
            IF ( @is_expiration_checked IS NOT NULL )
            BEGIN
              SET @tmpstr = @tmpstr + ', CHECK_EXPIRATION = ' + @is_expiration_checked
            END
        END
        IF (@denylogin = 1)
        BEGIN -- login is denied access
          SET @tmpstr = @tmpstr + '; DENY CONNECT SQL TO ' + QUOTENAME( @name )
        END
        ELSE IF (@hasaccess = 0)
        BEGIN -- login exists but does not have access
          SET @tmpstr = @tmpstr + '; REVOKE CONNECT SQL TO ' + QUOTENAME( @name )
        END
        IF (@is_disabled = 1)
        BEGIN -- login is disabled
          SET @tmpstr = @tmpstr + '; ALTER LOGIN ' + QUOTENAME( @name ) + ' DISABLE'
        END
        PRINT @tmpstr
      END
    
      FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @type, @is_disabled, @defaultdb, @hasaccess, @denylogin
       END
    CLOSE login_curs
    DEALLOCATE login_curs
    RETURN 0
    GO
    Note This script creates two stored procedures in the master database. The procedures are named sp_hexadecimal and sp_help_revlogin.
  3. Run the following statement in the same or a new query window:

    EXEC sp_help_revlogin

    The output script that the sp_help_revlogin stored procedure generates is the login script. This login script creates the logins that have the original Security Identifier (SID) and the original password.

Steps on the destination server (Server B):


  • On server B, start SQL Server Management Studio, and then connect to the instance of SQL Server to which you moved the database.
  • Open a new Query Editor window, and then run the output script that's generated in step 2 of the preceding procedure.

Monday, December 31, 2018

Amazon AWS, Create Access Key and Secret Key

AWS Amazon, Create Access Key and Secret Key

Creating, Disabling, and Deleting Access Keys for Your AWS Account Root User

  1. Use your AWS account email address and password to sign in to the AWS Management Console as the AWS account root user.
     
  2. Choose your account name in the navigation bar, and then choose My Security Credentials.
     
  3. If you see a warning about accessing the security credentials for your AWS account, choose Continue to Security Credentials
     
  4. Expand the Access keys (access key ID and secret access key) section.
     
  5. Choose Create New Access Key. If this feature is disabled, then you must delete one of the existing access keys before you can create a new key. For more information, see IAM Entity Object Limits in the IAM User Guide.
     
  6. A warning explains that you have only this one opportunity to view or download the secret access key. It cannot be retrieved later.
     
    1. Choose Show Access Key to copy the access key ID and secret key from your browser window and paste it somewhere else.
       
    2. Choose Download Key File to download the rootkey.csv file that contains the access key ID and the secret key. Save the file somewhere safe.
       



Thursday, December 27, 2018

IIS, Registering the ASP.Net with IIS server


  1. You need to start command prompt by typing cmd at the Run command and then execute the command prompt with Administrator rights by right clicking and choosing Run as administrator from the context menu.
     
  2. Then on the command prompt you need to navigate to the Directory that has the aspnet_regiis.exe file for that you need to type

      CD C:\Windows\Microsoft.NET\Framework64\v4.0.30319\
     
  3. Then you need to type the following command and hit enter to register ASP.Net with IIS

      aspnet_regiis -i
     

Tuesday, December 25, 2018

IIS, There was an error when trying to connect. Do you want to retype your credentials and try again?

IIS 8 error on windows server 2012 insufficient permission

There was an error when trying to connect. Do you want to retype your credentials and try again?

Details:

Filename: \?\C:Windows\system32\inetsrv\config\redirection.config Error: Cannot read configuration file due to insufficient permissions

screenshot:

Solution:

Steps to short out this issue:

  1. go to C:\Windows\Microsoft.Net\Framework64\v2.0.50727\CONFIG\machine.config
  2. here you got the redirection tag like the below

    <configurationredirection enabled="true" password="[enc:IISCngProvider:X0ObCWwZ4+PrTHiFVPtzFeCcL8u5P6KUOYfo1/0QrgZWATA5pKWqHvD8nL2crNJKyyqr4z/rBdLPjdRcaLxAMMj4l+lvp5EXXKSXueolvyGa34F4QZfbBVCM6oVNcq3M368TOTVjJv4POVFQWvu0MDVlGgReglXB+Lw5BRI4Htw=:enc]" path="C:\Windows\System32\inetsrv\config\import\" username="Administrator"> </configurationredirection"></li">

    you need to change this to

    <configurationRedirection />

  3. This will resolve the issue.
if you have missed your configuration in IIS then please follow the following steps:
  1. Open the IIS server and open the shared configuration, please check the below screenshots:
     

     
  2. please check the "Enable Shared Configuration" and select the path specified in the your configurationredirection (please check with yelow backgound)

    <configurationredirection enabled="true" password="[enc:IISCngProvider:X0ObCWwZ4+PrTHiFVPtzFeCcL8u5P6KUOYfo1/0QrgZWATA5pKWqHvD8nL2crNJKyyqr4z/rBdLPjdRcaLxAMMj4l+lvp5EXXKSXueolvyGa34F4QZfbBVCM6oVNcq3M368TOTVjJv4POVFQWvu0MDVlGgReglXB+Lw5BRI4Htw=:enc]" path="C:\Windows\System32\inetsrv\config\import\" username="Administrator"> </configurationredirection"></li"> 
  3. Then go to the machine.config file and revert the configurationredirection to previous setup that is

    <configurationredirection enabled="true" password="[enc:IISCngProvider:X0ObCWwZ4+PrTHiFVPtzFeCcL8u5P6KUOYfo1/0QrgZWATA5pKWqHvD8nL2crNJKyyqr4z/rBdLPjdRcaLxAMMj4l+lvp5EXXKSXueolvyGa34F4QZfbBVCM6oVNcq3M368TOTVjJv4POVFQWvu0MDVlGgReglXB+Lw5BRI4Htw=:enc]" path="C:\Windows\System32\inetsrv\config\import\" username="Administrator"> </configurationredirection"></li"> 
  4. Then go to Shared configuration and export the configuration 
  5. after this again change the machine.config configurationredirection  tag to

    <configurationRedirection />
  6. Now again import the Configuration from the Shared configuration from the Shared configuration in IIS.
This will also fix the IIS settings.

Tortoise SVN move SVN Repository To Another Server

How to take Backup and Restore of Tortoise SVN on window?

Back SVN
  1. Go to Run with Administrator privilege and then type cmd and open command prompt
  2. Run the following command

    svnadmin dump c:\Repositories\RepositoryName > c:\Repositories\svnbackup.dump

    Here
    1. c:\Repositories\RepositoryName is the source path of the repository
    2. c:\Repositories\ is the destination where the dump will create
    3. svnbackup.dump name of dump file

Restore SVN
  1. Go to Run with Administrator privilege and then type cmd and open command prompt
  2. Run the following command

    svnadmin load c:\Repositories < c:\Repositories\svnbackup.dump

    Here
    1. c:\Repositories is the destination path of the repository
    2. c:\Repositories\svnbackup.dump name of dump file that will be loaded

Saturday, December 15, 2018

C# - Copy DataTable from one DataSet to another

When we trying to add a DataTable (that is inside of a different DataSet) to new DataSet ds. If I add it directly, we will get the following error:

                   DataTable already belongs to another DataSet.

DataTable.Copy

use DataTable.Copy to create a copy of your data table; then insert the copy into the target DataSet:

dataSetX.Tables.Add( dataTableFromDataSetY.Table[0].Copy() );

DataSet.Merge

You could also use DataSet.Merge for this:

dataSetX.Merge(dataTableFromDataSetY); Note, however, that if you are going to use this method, you might want to make sure that your target DataSet doesn't already contain a table with the same name:

If the target DataSet doesn't contain a table by the same name, a fresh copy of the table is created inside the data set;

If a table by the same name is already in the target data set, then it will get merged with the one passed to Merge, and you end up with a mix of the two.

Monday, October 15, 2018

AWS - Covert AWS-supplied .pem files to the XML format

To use the RSA keys provided by AWS Account/Security in the .NET framework, you must convert the AWS-supplied .pem files to the XML format that the .NET framework uses. You can use below link to convert. 

 https://superdry.apphb.com/tools/online-rsa-key-converter

AWS - Message delivery to the remote domain failed for the following reason: The remote server did not respond to a connection attempt.

Error - Message delivery to the remote domain 'gmail.com' failed for the following reason: The remote server did not respond to a connection attempt.

 Amazon Web Services’ EC2 instances are throttled on port 25 by default as a spam prevention measure. This can cause connection issues when attempting to use SMTP to relay emails through Postmark in your EC2 instance. There are a couple ways to resolve this issue so that you do not receive connection errors when using Postmark in your EC2 instance. 

How do I remove the throttle on port 25 from my EC2 instance?

I'm having trouble sending email over port 25 of my Amazon EC2 instance, or I'm getting frequent timeout errors. How do I remove the port 25 throttle on my EC2 instance?

You can request Amazon Web Services to remove the throttling on port 25 using theRequest to Remove Email Sending Limitations form. Note: you must sign in with your root account credentials. Amazon Web Services will request that you provide a use case description with your request to remove the throttle. Once your request is approved, they will alert you via email that the block has been removed.



Wednesday, September 12, 2018

AWS - Enabling Enhanced Networking with the Elastic Network Adapter (ENA) on Windows Instances


AWS - Transfer the AWS EC2 Instances to ENA instances
Tags – Transfer m4 to C5 family, Transfer m4 to m5 family, Transfer m4 to R4 family, transfer to ENA instances

Steps are as follows:
1.    Install and configure the AWS CLI or the AWS Tools for Windows PowerShell on any computer you choose, preferably your local desktop or laptop. For more information, see Accessing Amazon EC2. Enhanced networking cannot be managed from the Amazon EC2 console.
2.    Configure the AWS Command Line Interface , use the aws configure command
$ aws configure
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: us-west-2
Default output format [None]: json

3.    Take an AMI of the Instance to have as a backup
4.    Install the driver to the instance
5.    Stop the Instance
6.    Change the Instance Type
7.    Run the Describe-Instance Command locally from the AWS CLI –
aws ec2 describe-instances --instance-ids instance-id --query “Reservations[].Instances[].EnaSupport"
8.    Run the Modify-Instance-Attribute Command locally from the AWS CLI –
aws ec2 modify-instance-attribute --instance-id instance-id --ena-support
9.    Run the Describe-Instance Command locally from the AWS CLI again to verify –
aws ec2 describe-instances --instance-ids instance-id --query "Reservations[].Instances[].EnaSupport"
10.  Start the instance and check the networking and sharing center
  

Resizing your Instances - http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2-instance-resize.html#resize-ebs-backed-instance

Tuesday, August 21, 2018

WordPress line break not Working

Many WordPress users struggle around this issue of WordPress line break not working. In this article, we discuss some of the possible ways to get around this issue.


1. Use empty classes in HTML Elements
You can make WordPress assume that your HTML elements contain certain attributes. This can be done by Adding attributes to the HTML elements with the use of empty classes. For example:
Avoid writing:
<p>
<br>
<span>
Instead, write:
<p class="">
<br class="">
<span class="">
2. Disable Autop formatting
The Autop() function in WordPress auto formats the paragraphs. The WordPress line break not working is due to the presence of a filter called “wpautop”. The “wpautop” filter executes whenever the content of a blog post is rendered.
We can easily use the remove_filter function to disable the wpautop filter. In the functions.php file you need to add the following code:
remove_filter ('the_content', 'wpautop');
If you use multiple themes, then you need to add this functionality as a plugin. You can place the code within a PHP file inside the /wp-content/plugins directory.

Published Post after Autop disabling

WordPress line breaks Fix1

3. HTML br tag not working: Use TinyMCE Advanced plugin

WordPress has a built-in editor known as the “Visual” editor. At the backend, the editor uses open source editor named “TinyMCE”. If you switch between the Visual Editor and the HTML(Text) editor, the TinyMCE functionality executes a backend filtration process. During this process, the empty tags and the
tags are removed from the post.
The TinyMCE-Advanced plugin adds the option to disable the automatic removal of and
tags. The option to disable/enable WordPress line break is present in the Settings->TinyMCE Advanced panel.
Tiny MCE plugin

Edit Post in Visual Editor without TinyMCE Advanced Plugin installed

WordPress line breaks issue21

Edit Post in Visual Editor with TinyMCE Advanced Plugin installed and disabled auto removal of tags:

 WordPress line breaks Fix21

4. Work with the HTML Editor

This is an easy solution for people who are familiar with HTML. You can avoid working with the Visual editor and switch to the HTML mode in the WordPress editor. The HTML mode lets you control the output and allows you to add or remove line breaks. Just use the
tag wherever you want a line break inserted.

5. Add a filter to replace
tag

Add a filter in the functions.php file which adds a clear attribute to the
tag. When the attribute is added, the
tag is not removed by WordPress.
function clear_br($content) { 
return str_replace("<br/>","<br clear='none'/>", $content);
} 
add_filter('the_content','clear_br');

Post before adding filter

WordPress line breaks filter2

Published post after adding filter

WordPress line breaks filter

6. Create a WordPress Line Break (br) Shortcode

You can add a shortcode to fix the line breaks not working issue in WordPress.
Insert the following shortcode code into the functions.php file:
function add_linebreak_shortcode() {
return '<br />';
}
add_shortcode('br', 'add_linebreak_shortcode' );
Now insert the shortcode shown below wherever you want to insert a space.
[br]

Adding Shortcode in Text Editor

 WordPress line breaks shortcode

Edit Post in Visual Editor

WordPress line breaks shortcode2

Published Post after Adding Shortcode

WordPress line breaks shortcode3

7. HTML Br tag not working – Use CSS

Some developers believe
tags should not be used for styling pages. HTML is a semantic language, not to be used for defining positioning, styling or layout information. Use CSS to generate the style or size of paragraph margins using stylesheets. If you have basic knowledge of CSS, then all you need to add paragraph spaces is add a bottom margin to the tag for the paragraph.
  1. Open the WP admin panel.
  2. Select Appearance > Editor.
  3. Select the file style.css file on the right side. Locate the tag in the style.css file.
    Add the following lines to add gaps above and below the paragraph:
    padding-top:1.0em;
    
    padding-bottom:1.0em;
    Example:
    p {
    margin: 0 0 1.5em;
    }
    After adding those two lines, it will look like this:
    p {
    margin: 0 0 1.5em;
    padding-top:1.0em;
    padding-bottom:1.0em;
    }
  4. Save the file.
All paragraphs get a space above and below. Note that this would add the same amount of space above and below all paragraphs.
 WordPress line breaks margin


Note: this article is taken from https://blog.templatetoaster.com/wordpress-line-break-not-working/