Tuesday, 21 August 2018

SQL Server Error 5123 Attach Database - Resolution

SQL server error 5123 occurs when users want to attach the database, which has been placed on different locations. This error is a kind of permission error that occurs in SQL Server. As we all know, the .mdf is a primary database file and .ldf file represents the log file associated with a primary database file. Regardless of attaching a primary data file via SQL Server Management Studio, sometimes it becomes very difficult to open it. On the other hand, this error may be encountered when there are several logins for attaching or detaching the database. Therefore, in the following section, we are going to discuss a manul procedure to resolve Microsoft SQL Server error 5123 in an absolute and reliable way.

Microsoft SQL Server Error 5123 – Reasons

Let us take a look on the reasons why Microsoft SQL server error 5123 occurs.

  • This error occur if you detach the last database with different logins and then, try to attach a database with different logins.
  • In Microsoft SQL Server this error generates at the time when the entire process is running on the Server but it has no permission to run a program folder.

To overcome this problem we have to change the permission or add permission as the owner of .mdf and .ldf files.

Fix MS SQL Server Error 5123 Attaching Database - Manual Steps

Follow these steps to solve SQL error 5123. Some of the steps are listed below:

  • Right-click on MDF file that you need to attach
  • Then, choose Properties to check the permissions of MDF file.
  • Click on Add button to grant any other login permission or and provide the full login control.

Moreover, you can perform this for an associated .ldf file and again, you can try to attach.

You can also try "Run as Administrator" rather granting permission to everyone.

Attach the Database in Microsoft SQL Server

1. Using SQL Server Management Studio (SSMS)

  • Log in to SSMS using a valid domain name and Windows Authentication
  • Click on the Object Explorer and then, select 'Databases' to view the list of existing databases.
  • Right-click on 'Database' and choose 'Attach' from a drop down menu
  • A new Attach Database Window will appear on the screen, now click on 'Add' button
  • After that, you can select the database that you want to attach.
  • The database window will verify the MDF and LDF files. Then, click the OK button.

Here, you can see all the attached database files in SQL instance.

2. Using Transaction SQL (T-SQL)

With the help of sp_attach_db stored procedure, users can easily attach the databases in MS SQL Server. Let us have a look:

sp_attach_db [ @dbname= ] 'dbname'
, [ @filename1= ] 'filename_n' [ ,...16 ] 
[ @dbname= ] Is the name of database that can be attached to a server.
[ @filename1= ] 'filename_n' Is the physical name, which includes location of a database file.

How to Solve Microsoft SQL Server Error 5123

If the above-stated method is not working well or you want quick solution to Fix SQL MS SQL Server Error 5123, then you can go for an automated approach ie SQL Database Recovery Tool. The tool recover database from corrupted SQL MDF File. Not only this, it is able to recover deleted database objects of SQL version 2017, 2016, 2015 & its below version.

Conclusion

SQL Server Error 5123 Access Denied error is one of the common error occur which SQL DBAs faces. The blog covers the possible reason behind this error and discusses the resolution to solve SQL Server Error 5123.

Tuesday, 7 August 2018

Generate Script in SQL Server With 6 Simple Steps

“I am a new user of SQL Server so I have very limited knowledge of its features. I would like to know how to generate script with data of SQL Server 2016 database. As I have mentioned, I am unaware of this process. Can anyone help me by telling how to generate scripts from SQL Server data? Thanks.”

Are you looking for a way for script generation in SQL Server ? If yes, then continue reading this post to learn two solutions of this problem.

SQL Server is widely used around the world for managing database. It contains features that can generate scripts that can be used for creating databases, inserting data, making tables, functions, views, etc. For these reasons, many SQL users want to generate script with data in SQL Server 2017. Despite wanting to generate the script, many users fail to do that because of their lack of knowledge about the procedure.

Considering this situation and user demand, this write-up will discuss different ways of generating scripts in SQL Server data.

Read on to learn more about it.

How to Generate Script in SQL Server with Data

There are two different methods of generating script. One is called the manual method and another is named automatic method.

In this section, we will going to discuss two methods to generate SQL Server script. You can choose one according to your convenience.

Method 1: Manual Technique

Follow these steps to generate SQL scripts manually

  1. In order to perform this process, First open SQL Server database. Now, right-click on the Database. Select the options Task and then click Generate Scripts.
  2. An introductory screen will open and you need to click on the Next button to proceed further.
  3. Now, choose the database object that you need. Click on Next.
  4. On the next page, users will be asked to configure settings regarding how the script should get published. After choosing the settings, click on Advanced button on the same page.
  5. For the option ‘types of data to script’, choose ‘Schema and data’ from the drop-down menu. Then click OK>> Next.
  6. Click on Finish when it is done generating scripts. You can check the script file now and run it if needed.

Method 2: Automatic Technique

If user downgrade the SQL Server version and want to generate SQL script, the user will not be able to generate it due to the compatibility issue. For this users can try an automated solution to generate SQL Server script with data that is using SQL MDF Repair Tool. Using this application, users can easily generate scripts with data in SQL Server 2017, 2016, 2015 & all its below versions.

This software can also recover deleted data from SQL database and create scripts out of them. Even if some of your data is damaged, this tool can easily recover them and then make scripts. To generate SQL Server script with data with the help of this application, users have to perform the below steps:

  1. Download and launch the tool. Add the SQL database file for which you want to generate script.
  2. Once the file is loaded, you can preview all of its contents.
  3. Click on Export button from the menu options.
  4. Select “SQL Server Compatible Scripts” as the export as file type.
  5. Also choose the option “With Schema & Data” and then click on Save.
  6. The tool will generate script of selected SQL Server data.

Conclusion

If users need to generate script with data in SQL Server , they are landed on correct page. Here, we have discussed two solutions for generating SQL scripts . Users can pick any one of them to generate SQL scripts.