Tuesday, 29 May 2018

Attaching a SQL Server Database to DB server through T-SQL

While working to develop a SIKULI script to run on multiple machines, i came to a situation  to attach a database in every machine. As sikuli is not much flexible, i choose to attach the db via T-SQL .

I opened the SQL server  management studio in the remote machine and logged into that with SIKULI script. so finally find the below code to be run on a new query window.

CREATE DATABASE RAPOS_Replication  
    ON (FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\RAPOS_Replication.mdf'),  
    (FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\RAPOS_Replication_Log.ldf')  
    FOR ATTACH;

With sikuli, its some thing like below:

        type('CREATE DATABASE RAPOS_Replication')
        type(' ON (FILENAME = \'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\RAPOS_Replication.mdf\'),')
        type(' (FILENAME = \'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\RAPOS_Replication_Log.ldf\')')
        type('FOR ATTACH;'+Key.ENTER+Key.F5)
        wait(3)

No comments:

Shrinking the size of Oracle Virtual Box

First, zero fill your virtual disk. Boot the VM and run: sudo dd if=/dev/zero of=/bigemptyfile bs=4096k status=progress sudo rm -f /bigempty...