How To Repair A Suspect Database In MSSQL

The database may occasionally be marked as SUSPECT when you connect to a SQL Server instance. You won’t be able to connect to the database to read and write data in this situation. The procedures you must follow to restore your database that has been marked as SUSPECT are discussed in the article.

Reasons of this error

Here are some following causes due to we have to face the suspected database error.

  1. Restart or shut down the Database without shutting down the SharePoint server.
  2. The database could have become corrupted.
  3. There is not enough space available for the SQL Server to recover the database during startup.
  4. The database cannot be opened due to inaccessible files or insufficient memory or disk space.
  5. The database files are being held by the operating systems, third-party backup software etc.
  6. There was an unexpected SQL Server Shutdown, power failure, or hardware failure.

Resolutions

Here are a few steps to resolve this issue. First, make sure you have Microsoft SQL Server Management Studio in your system.

1.   First, open your Microsoft SQL Server Management Studio and fill in your database credentials to connect to your database.

2.   Then right-click on your suspected DB and click on the New Query button to write a query.

3.  After that run the below commands one by one Here you need to replace [YourDatabase] with the name of your database Name.

a. Reset the database status to clear any error flags.

EXEC sp_resetstatus [YourDatabase];

This command resets the status of the specified database. If a database is marked as “suspect” or in a similar state, this command can clear that status. It’s the first step to attempt to bring the database back online.

b. Put the database into a state where it can be safely checked and repaired (emergency mode).

ALTER DATABASE [YourDatabase] SET EMERGENCY

This command sets the database to emergency mode. Emergency mode is a special state used for troubleshooting. In this mode:

  • The database is set to read-only.
  • Only members of the sysadmin role can access the database.
  • It’s used when the database is severely damaged and cannot be accessed normally.

c. Check for any issues in the database.

  DBCC checkdb([YourDatabase])

This command runs the DBCC CHECKDB utility, which checks the physical and logical integrity of the entire database. It identifies any corruption or issues within the database.

d. Ensure no other users are connected to interfere with the repair process (single-user mode).

  ALTER DATABASE [YourDatabase] SET SINGLE_USER WITH ROLLBACK IMMEDIATE

This command sets the database to single-user mode with immediate rollback. This means:

  • Only one user can access the database at a time.
  • Any other connections to the database are terminated immediately.
  • It’s necessary to prevent other users from interfering with the repair process.

e. Repair the database, accepting that some data might be lost to fix the issues.

  DBCC CheckDB ([YourDatabase], REPAIR_ALLOW_DATA_LOSS)

This command runs the DBCC CHECKDB utility again, but this time with the REPAIR_ALLOW_DATA_LOSS option. This option attempts to repair any detected corruption, but it can result in data loss because it may delete or modify corrupted data to make the database functional again.

f. Return the database to normal operation (multi-user mode).

 ALTER DATABASE [YourDatabase] SET MULTI_USER

This command sets the database back to multi-user mode, which allows multiple users to connect and use the database as normal.

4. After Execute the script refreshes the database.

For any queries, you can reach us at support@knowband.com. Knowband provides best-in-class solutions for everything eCommerce. We also offer custom development of all sorts like Plugins and Mobile apps for Prestashop, and Opencart. Magento and Magento 2. Click here to know more.

Knowband Mobile App Builder

Get the mobile app created for your store in a few hours with the Knowband Mobile App Builder Module.

KNOW MORE

Recommendations for you:

We highly recommend our No Code Mobile App solution to all eCommerce store owners. Know more:

 

How to fetch data from Firebase in Swift Language (iOS)?

Objectives of the blog

After reading this blog we will be able to understand the process to fetch data from Firebase. This process includes installation of Firebase SDK and implementation of code to fetch data from Firebase.

Pre-requisites

We need to write swift code to fetch the data from Firebase. For this first we will have to create the Firebase project. Follow the steps given below to create the Firebase project –

1. Go to https://console.firebase.google.com

2. Then you will have to create Firebase project by clicking on “Add Project” button

 

3. You need GoogleService-Info.plist file for iOS SDK as this file contains the details of the Firebase project which are used by Firebase SDK

4. Then add the plist file in the project

5. Add the following code before the return statement within application(_:didFinishLaunchingWithOptions:) in AppDelegate.swift file

FirebaseApp.configure()

6. Then go to “Database” option from the left menu.

 

7. Select “Realtime Database” and that is the database for the Firebase project. All the data that is stored in or fetched from is from this location.

8. Firebase setup is completed

Now you will have to download Firebase SDK in the swift. For this you will have to install the following pods.

  1. pod ‘Firebase/Core’
  2. pod ‘Firebase/Database’

Let suppose you have the following data in the given structure in the Firebase database –

// The root of the tree
{
  // grocery-items
  "grocery-items": {
 
    // grocery-items/milk
    "milk": {
 
      // grocery-items/milk/name
      "name": "Milk",
 
      // grocery-items/milk/addedByUser
      "addedByUser": "David"
    },
 
    "pizza": {
      "name": "Pizza",
      "addedByUser": "Alice"
    },
  }
}

 

After successful installation of the pods, we can move on to the coding part.

Code Implementation

All the data points/nodes are used to access data from Firebase database. We create references to the nodes and then fetch data from that node.

In other words a Firebase reference points to a location in Firebase where data is stored.

First we will have to create reference to the root node of the database structure –

let ref = Database.database().reference(withPath: "grocery-items")

or the following way can be used –

 

let rootRef = Database.database().reference()
let ref = rootRef.child("grocery-items")

Reference to the child node which is “milk” can be created using the following code –

let milkRef = ref.child("milk")

Asynchronous listener can be attached to a reference in order to retrieve data from Firebase using observe(_:with:) method.

The following code will fetch the data and keep listening to the data changes on the database. As soon as any change is made in the database, the new snapshot of the node/reference is fetched and we get the updated data as soon as any change is made in the database.

 

ref.observe(.value, with: { snapshot in
  // This is the snapshot of the data at the moment in the Firebase database
  // To get value from the snapshot, we user snapshot.value
  print(snapshot.value as Any)
})

Then the snapshot values can be parsed and used in the app.

One big advantage of using observe method over observeSingleEvent method is that you don’t have to call the function again and again as the updated data is fetched from the database as soon as any value is changed in the database.

Summary

Now you should be able to fetch the data from the Firebase database in swift using Firebase SDK.

Please feel free to get in touch with us at support@knowband.com for any issues.

We also provide No Code Mobile App solutions for Prestashop, Opencart, Magento 2 and Woocommerce. Know more here: