How to restore a SQL Server Database to a new location and name


This post explains how to restore a full database backup to a new location and with a new name. This procedure enables you to move a database or create a copy of a database on either the same server instance or a different server instance. This example is usefully for a LocalDB instance of SQL Server 2012.

1. First, you need to know the logical database names (ex. “MyDatabase_data” and “MyDatabase_log”).

RESTORE FILELISTONLY FROM DISK = 'C:\MyBackup.bak'

2. Next, you can restore the backup to a new Database.

RESTORE DATABASE MyNewDataBase
 FROM DISK = 'C:\MyBackup.bak'
 WITH RECOVERY,
 MOVE 'MyDatabase_Data' TO 'C:\Data\NewData.mdf',
 MOVE 'MyDatabase_Log' TO 'C:\Data\NewData_Log.ldf'

To execute these commandes, you can use SQLCMD utility (available in C:\Program Files\Microsoft SQL Server\110\Tools\Binn).

Tagged with: , ,
Posted in General, SQL Server, Tips and others

Add “Extract MSI” command to Windows Explorer Context Menu


Many software or tools are provided as MSI files. There are some tools like LessMSI, but there is a simpler way to add a “Extract MSI” command to your Windows Explorer Context Menu. However, if you make a small registry modification (without Windows reboot), you can add the ability to Extract these file…

Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Classes\Msi.Package\shell\Extract MSI\command]
@="msiexec.exe /a \"%1\" /qb TARGETDIR=\"%1 Extracted\""

Download this file and merge with your registry. Right-click on a MSI file and click on the new command “Extract MSI”.

Tagged with:
Posted in General, Tips and others

Changing the scope of the AssignedTo field in TFS 2012 Work Items


By default, Team Foundation Server presents all “available or existing” users when you assign a work item to somebody. Of course, it’s possible to customize TFS to display only members of one or multi groups in Assign To field.

To do that…

  1. Open Visual Studio (with Team Foundation Server Power Tools).
  2. Go to Tools / Process Editor / Work Item Types / Open WIT From Server.
  3. Select your Team Collection and your Work Item Type.
  4. Select and edit « Assigned To » Field.
  5. Add a new Rule « AllowedValues » and a new value « [project]\Contributors » (see picture below).
  6. Close all dialog boxes.
  7. Save the WIT file to the server (CTRL+S).

Note the [project] should be as is and not substituted for your own project name.

TFS-AllowedContributorsOnly

Tagged with:
Posted in Team Foundation Server, Tips and others

How to sign an assembly in Visual Studio, from a validated certificate (Verisign, Globasign)


If, like me, you want sign your assembly from Visual Studio, you received probablely an error message like “Cannot import the following key file … The key file may be password protected”.

First, read an excellent article about Differences between certificate signing and strong naming (from Eric Lippert).

Next, use this procedure to transform your Code Certificate purchased from Verisign or Globasign to a valid certificate for Visual Studio Strong Name.

1. Download OpenSSL from this site.
2. Execute the following commands to export to a key file usable by Visual Studio.

openssl pkcs12 -in GlobalSignCodeCertificate.pfx -out BackupCertFile.key
openssl pkcs12 -export -out CertFileToSignWith.pfx -keysig -in BackupCertFile.key

3. Then in the project properties of Visual Studio, you can use the PFX file.

Capture

Tagged with: ,
Posted in General

How to set Proxy Credentials in Visual Studio 2012


When you want connect Visual Studio 2012 to Team Foundation Server in a corporate company with a proxy server, and if this proxy requires your Credentials (login / password), you must use this procedure:

  1. Open TOOLS / Extensions & Updates.
  2. Click on Updates… in the left-hand menu.
  3. There will be a failure notice on screen and a link to enter your credentials. Click it and enter them.
  4. Close the Extension manager.
  5. Click TEAM > Connect to TFS server… and it will work!

See this small video: 

Tagged with: , ,
Posted in Uncategorized

Backup all databases in Microsoft SQL Server


Find here, a cool SQL script to backup all SQL Server databases. Of course, you can put it in a Scheduled Job to execute each night.


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

--specific location
SET @path = 'E:\Backup\Database\'

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

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

OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @name

WHILE @@FETCH_STATUS = 0
BEGIN
 --SET @fileName = @path + @fileDate + '-' + @name + '.bak'
 SET @fileName = @path + @name + '.bak'
 BACKUP DATABASE @name TO DISK = @fileName WITH INIT, COMPRESSION

FETCH NEXT FROM db_cursor INTO @name
END

CLOSE db_cursor
DEALLOCATE db_cursor

Tagged with: ,
Posted in SQL Server

How to align form controls in Html5 and CSS3


HTML5 is coming and some greats features can align (left and right) and resize form controls (textbox, list, …) like in a Desktop application. unfortunately, it is not yet compatible with all modern browser.

To display your controls in 2 columns, use this code and associated CSS.

ResizeFormControls

<div class="TwoColumns">
    <!-- First column -->
    <div class="Column">
        <div>
            <label for="txtFirstname">First name:</label>
            <input type="text" name="txtFirstname" value="Denis" />
        </div>
    </div>

    <!-- Second column -->
    <div class="Column">
        <div>
            <label for="txtLastname">Last name:</label>
            <input type="text" name="txtLastname" value="Voituron" />
        </div>
        <div>
            <label for="cboSex">Sex:</label>
            <select name="cboSex">
                <option>Girl</option>
                <option>Boy</option>
            </select>
        </div>
        <div>
            <label for="txtPhone">Phone:</label>
            <input type="text" name="txtPhone" value="02/123.45.67" />
        </div>
    </div>

</div>

And the CSS file is:

body
{
    font-family: 'Segoe UI', sans-serif;
    font-size: 10pt;
}

label
{
    margin: 4px 0px 2px 0px;
    float: left;
    width: 110px;
}

input, select
{
    font-family: 'Segoe UI', sans-serif;
    font-size: 10pt;
    margin: 2px 0px 2px 0px;
    padding-left: 5px;
    height: 20px;
    width: -webkit-calc(100% - 20px - 110px);
    width: calc(100% - 20px - 110px);   
}

select
{
    height: 24px;
    width: -webkit-calc(100% - 11px - 110px);
    width: calc(100% - 11px - 110px);   
}

.TwoColumns
{
    -webkit-column-count: 2;
    column-count: 2;
    -webkit-column-gap: 0px;
    column-gap: 0px;
    min-width: 400px;
}

.Column
{
    -webkit-column-break-inside: avoid;
    break-inside: avoid;
}
Tagged with: ,
Posted in Uncategorized
Follow me
   RSS Feed    Twitter    Linked In

Write you email address to subscribe at this blog and to receive new posts by mail.

Join 8 other followers

Who I am?


Follow

Get every new post delivered to your Inbox.