Friday, 21 September 2018

Best Trick to Extract Data From SQL Server MDF File Instantly

SQL Server is a relational database management system in technology field it supports more than one transaction processing. MDF is utilized to save information like views, stored information and so on and secondary is .ldf file, that stores transactional information of its related primary database file MDF. Moreover, .mdf is a foremost database file of SQL Server, then, it's necessary to keep all the crucial data secure in case of mishap.

Often times, user try to extract data from MDF file as .mdf file sometimes become inaccessible, if in case it's associated with .ldf file get damaged or lost due to any cause. Also I saw bundled queries on how to extract data from SQL File. Thus, we are discussing some workarounds to resolve and fix the issue of the user to extract data from corrupt mdf file.

Extract Data from MDF File - Manual Workarounds

Mainly, there are two various tricks for extracting data from .mdf file. User can opt any one of them as per their comfort. First one is, by utilizing “T-SQL Script” and another one is “SQL Server Management Studio”.

The techniques with their steps are listed below, you have to follow all the given steps in sequencially to get positive outcome.

Workaround 1: Using T-SQL

Step 1: Firstly, to extract data from .mdf file in SQL server by using T-SQL script follow this below listed command.

Step 2: Lastly, after using the listed command will attach the database in SQL Server, whether the LDF file is lacking to the related .mdf file. Moreover, the “ATTACH_REBUILD_LOG” will create a fresh transaction log file or generate a new database.

Workaround 2: Utilizing SQL Server Management Studio(SSMS)

Step 1: Start SQL Server Management Studio (SSMS) application into your machine.

Step 2: Now, connect the application with SQL Server instance of Database Engine.

Step 3: Here, in an option of “Object Explorer” you have to choose, the “Databases” option and then Right-click on it. Furthermore, you will have to hit on “Attach” to move forward.

Step 4: Afterwards, in “Attach Database” wizard, select “Add” button to spot the desired MDF file that you need to attach.

Step 5: Simply, go to the location where you have stored your .mdf file and choose the .mdf file then select “OK” button.

Step 6: Once again, in “Attach Database” wizard opt “Ok” button to extract MDF file in SQL Server effectively.

Step 7: Finally, after applying the above mentioned steps on your SQL Server, you can view the attached database on your databases node.

Drawbacks of Perform Extraction Manually

The above-mentioned manual method to extract data from MDF File include some constraints that affect the procedure effectively. Some of them are listed below:

  1. The MDF file that you need to attach wants full access control and full permission.
  2. Check that you are trying to attach it in correct version not in higher version or in lower version as well.
  3. It is difficult to execute by a novice user because, it includes some technical knowledge.
  4. This procedure might be loss your crucial data while, extracting data from MDF file to SQL server.

Extract Data from SQL Server MDF File - Professionally

As-per the above-mentioned limitations of manual approach, a user can go with an alternate method that, will help to perform the extraction task positively. This is an appropriate way to resolve the issue this is a third-party application such as SQL Recovery software. With the help of this utility user can easily and simply repair corrupted .mdf & .ndf SQL Server database and extract data from corrupt mdf file.

This software furnishes an easy-to-use and understandable interface even, a novice user can also execute the task without taking an expertise help. This utility, extract data from MDF file without losing a bit of users data. SQL recovery contains an outstanding features, some of them are listed below:

  1. Recover SQL Database primary as well as Secondary
  2. Retrieve deleted SQL server database table's Data
  3. Quick & advanced option for scanning
  4. Software supports ASCII and Unicode XML datatype
  5. Repair all versions of SQL Server 2017, 2016 & below version.
  6. Option to Auto-fetch SQL server version while extracting

Working Steps of SQL Recovery Application

Step 1: Download and install the SQL recovery software into your local machine. The interface of the utility as shown in the below picture:

Step 2: Now, choose an option “Advance Scan” and then hit on “Auto detect” option if you don’t know the version of SQL Server or opt manually to detect MDF file version properly.

Step 3: Here, you have to review the components of MDF and NDF Files

Step 4: Finally, click on “Export” to successfully export the MDF file with only Schema and with Schema or Data.

Final Verdict

We explained two different ways to extract data from MDF file to SQL server effectively. As you can see that the manual techniques have some constraints that affects the procedure positively. So, we describe an alternate approach also to open and view the data of SQL MDF File. With the help of the software, user can easily and simply execute the extraction procedure effortlessly. Afterwards, it all depend on the user that which, one method they want to opt. User can go with any one of them as per their requirement.

Tuesday, 11 September 2018

Steps to Restore Database from Backup File in SQL Server

Overview

In most of the cases, users create a backup file of their database on their machine. This help the users to perform recovery at the time of any disaster, or manage large amount of database onto the SQL server. However, users generally knows the way to create a backup of a database on their machine, but are unaware from the way to restore database from .bak file on SQL Server. Therefore, this blog will help such users to restore database in SQL server either by using query or SSMS.

Steps to Recover SQL Server Database From .bak File Using SSMS

In order to restore SQL Server database from .bak file, it is mandatory to have a backup file on computer system. In addition, go through following set of procedure for recovering SQL server database from a backup file:

  • Launch the SQL Server Management Studio on your machine. Then, from the left-hand side menu of the management screen, right click on Databases option and then select Restore Database option from it.
  • A Restore Database Window will appear. From this Window, check the checkbox of Device option
  • Click on the Browse button from the restoration window
  • Now a backup device window will appear in front of you. In this window, you have to choose File as backup media type and then click on Add button
  • Now navigate to the location where the backup file is stored. Click on the file having .bak file extension for selecting it and then click on OK button
  • Analyze the selected database file from middle pane area of backup device window and then click on OK to continue further
  • Click on OK button of the Restore Database window. This will start the procedure of recovering the server database from a backup file
  • After the completion of restoration procedure, a message window will appear that indicates that the complete data is now recovered from the BAK file. Click on OK button to terminate the current settings window
  • Now either press F5 from your keyboard or click on Refresh button of SQL server Management Studio. This will display the database restored from the backup file

Finally, you will be able to see database of your backup file, on left-hand side panel of management studio. You can click on expand button to see further tables of the restored database.

Steps To Restore Database from Backup In SQL Server Using T-SQL

In this case, if the database already exist, then data of existing database will overwrite the files or tables with new one. If database exist, then follow the following commands:

  • Launch a SQL query window on your server
  • Set the database of the server in Single User Mode by executing following command:
    ALTER DATABASE < Database Name > SET SINGLE_USER with Rollback IMMEDIATE
  • Run the following command for restoring the database from backup file:
  • RESTORE DATABASE < Database Name > FROM DISK = ‘< Location where BAK file is stored >’ WITH REPLACE, STATS = 5

If the database does not exist, then execute following command in query window of the server:

RESTORE DATABASE AdventureWorks FROM DISK = ‘< Location of BAK file with file name >’

Observational Verdict

In this blog, users can find strategy to restore database in SQL server from backup file using query or SSMS. In addition, it is also applicable to all other versions of the SQL server. The most easiest way is to recover SQL server database from .bak file using SQL server management studio .It is quite easy to access, in comparison to query procedure. This step guide is sufficient to recover SQL server database from backup file and thus no need of any technical expert to perform the same. However, both the procedures are foolproof and could be accessible by a novice users also and it is recommended to validate your backup before going to restore it. Because, Sometimes, it may not be possible to restore a backup due to a corrupt .bak file. In this worst scenario one can try page checksums or use third party SQL Backup Recovery Tool to overcome with this situation.

Monday, 10 September 2018

Different Ways to Handle Deadlock in SQL Server

Introduction To Deadlock

Deadlock in SQL server is a condition in which two or more system server processes IDS (SPIDs) are waiting for a resource. No process can get the resource as the other processes are preventing it from getting the resource. It is a very common issue in SQL Server, whenever this situation occurs in the system, the server will choose one of the process as a victim and rollback that process. After it rollbacks the victim process, it allows other processes to execute as there is no other way to resolve the conflict.

Lock Manager

The thread of lock manager checks the deadlock condition. When the lock manager algorithm finds a deadlock, it will select one process as a victim and send error message 1205 to the client. Lock manager then kills that selected SPID. Killing the victim SPID will free up the resource and will allow other processes to continue with the resource.

How To Identify Deadlock in SQL Server

First, to identify the deadlock, one should gather information about suspected processes and resources. To get this information one needs to add the -T1204 and -T3605 startup parameters or we can call Trace Flags to SQL server.

Steps for adding startup parameters:

  1. Start SQL Server Enterprise Manager.
  2. Select and then right-click the server.
  3. Click on Properties.
  4. Go to the Startup Parameters.
  5. In the Startup Parameters, enter-T1204 in the Parameters text box.
  6. Then click on Add.
  7. Again in Parameters text box, type -T3605.
  8. Then click on Add.
  9. Click on OK.

The startup parameter -T1204 will gather information about processes and the resource when the lock manager encounters a deadlock. Whereas -T3605 startup parameter write this collected information on a log file.

Three Events to capture Deadlock in SQL Server

User can also go for the profiler to capture the deadlock, there are three events that can capture the deadlocks. These events are present in Lock event class.

  • Deadlock graph – Deadlock graph provides XML description of the deadlock.
  • Lock: Deadlock – It indicates the two processes that has deadlocked each other in order to acquire the resource.
  • Lock: Deadlock Chain – It generate all the events that causes the deadlock condition.

How to Handle Deadlock in SQL Server

To handle deadlock in SQL Server, user can go for following techniques given below:

The Lock Manager

The SQL server detects the deadlock victim by two ways:

  • Lock Manager will assign the priority to the processes competing for the resources using Deadlock_Priority. The process with lowest priority will always be considered as deadlock victim.
  • If two or more processes have same priority then, the process that has lowest cost will be chosen as victim.

Trace Flag 1204

It captures the details of deadlock in SQL Server and provides information about the node involved in deadlock condition. User can use DBCC TRACEON(1204, -1) format to capture the details of involved processes and resource.

Trace Flag 1222

It returns the deadlock information using XML format, the Flag 1222 captures the graph, which is in more comprehensive format as compared to Output information of Flag 1204. It captures the deadlock events in the form of graph.

WMI Provider

The WMI (Windows Management Instrumentation) Event Provider is used for creating SQL Server Agent alerts that respond to specific events. For later analysis, it generates an alert that saves XML deadlock graph events in a table. SQL Server Agent submits a WQL (WMI query language) request, receives the WMI events, and runs a job in response to the event.

By Capturing The Graph

In this, user will get the information about processes and resource involved in deadlock using graph. It offers the XML deadlock graph event in profiler, which captures more information about deadlock events than trace flag 1204.

Conclusion:

In this article, we have captured the different ways of handling deadlock conditions in SQL Server and the reasons that causes the deadlock in the server. By using techniques mentioned above, one can easily find the events or different processes and resource that are involved in deadlock condition.

Friday, 7 September 2018

Best Way to Fix Corrupted SQLite Database

Corruption is one of the common scenarios nowadays. It can occur in any platform or file format, for that matter. Similarly, Android SQLite database can be corrupted due to various reasons. Therefore, in this blog, we will introduce a best to for the recovery of damaged Android SQLite database. Before that, let learn some crucial details about Android SQLite database.

Android save the data via SQLite database engine and it is a stand-alone transactional engine, which allows users to access and manage database. It does not need any dedicated server process. Many application, as well as platforms beyond mobile OS Android, use SQLite. Dissimilar to desktop-based databases, it (SQLite) removes the features, which are not essentially useful and as an outcome attains minute footprint. DB systems use static typing; on the other hand, SQLite prefers the manifest typing. It drives the data information responsibility to compute languages such as Java. This maps database structure to the high-end types.

Reasons to use Android

One of the major reasons behind this is that SQLite is reliable. Most of the plans codes are dependent on library testing. Moreover, the library has such a structure that it has the ability to handle the failures of the system like disk errors, power failure, or low storage memory. Some more grounds due to which Android utilizes SQLite:

  • Need No setup and Installation: SQLite does not need any administration, as it is an independent platform. Moreover, it requires no administrator for managing data.
  • Use Data in Other Platforms: The database, which is generated in SQLite is in the stable format as well as with backward capability. Therefore, it can used on the older version too.
  • Creation of Dedicated Database File: It produces a single database for the complete entry & information storage when uses on the platform or on an application.
  • Static Typing vs. Manifest Typing: SQLite database is not the property of column storing value, unlike SQL database, but of the value itself. Therefore, any of the value can be saved in the random column regardless of the declared type of column.

SQLite has various benefits but is prone to corruption as well. Let us, how to resolve the damage from unhealthy Android SQLite database.

How to Fix Corrupt SQLite Database

There are many utilities available in the online market to accomplish this task. This is all because of the immense increase in technology. However, we cannot trust any random software. Moreover, if users made the wrong choice they may have to face negative consequence of the same.

SQLite Recovery tool helps them out in such conditions. It is an advanced application and allows users to repair and recover the SQLite database without any difficulty. After the recovery, users can even export the files into various three different file formats, which includes SQLite, MS Access, or even any other database keeping the entire data safe and secure. It supports numerous DSN such as SQL database & Microsoft Access. You just have to follow these steps as stated below:

  • To begin the process, head to Start >> All Programs >> Sqlite Database Recovery
  • Now, click Browse followed by a hit on Open
  • The scanning will begin, click on OK after its completion
  • After this, all the details of SQLite database, which you picked up, will display. You need to click on the Close button after viewing it
  • Then, click Export for exporting database into a healthy content.
  • Select one file format, from the options. Your data will be migrated into that file and then click on OK
  • Provide the data type mapping and to confirm it, click OK
  • After this, pick the destination path for saving SQLite database. Then, hit on OK
  • In the next step, hit on OK when you see the complete details of the exported file
  • Now, close report & exit. After you do this, go to “Other Database” radio button to migrate database in other format & continue
  • Pick any of the file formats from the options, and then click on OK button
  • Once it is done, select type of SQLite data and map it to all other data types. Hit on OK to continue
  • A report will be generated after the progress bar goes to 100 percent, this indicates the completion of the process. You need to click on Close after this.
  • Again click on the button of OK for confirming completion of the procedure
  • In the final step, exit the application, by click on Yes button.

Wrapping It Up

There are various reasons behind the Android using SQLite. However, it can be damaged anytime. Therefore, in the above blog, we have learned a method to repair Android SQLite Database after it gets corrupted. Many professionals have successfully used this method and recovered their data.