回覆列表
  • 1 # 使用者6704656755005

    在MS SQLSERVER中一直有這樣的問題,SQLSERVER的狀態"置疑",原因約有以下幾條:

    2.硬體(HD)損壞,造成日誌和資料檔案寫錯誤;

    3.硬碟的空間不夠,比如日誌檔案過大;

    解決辦法:

    最簡單的辦法是有資料庫的全備份,然後恢復即可.

    步驟:

    USE MASTER

    GO

    DROP DATABASE DB_SUEPECT

    2.建立同名的資料庫:

    USE master

    GO

    CREATE DATABASE DB_SUSPECT

    ON

    ( NAME = DBNAME_DAT,

    FILENAME = "C:",

    SIZE = 10,

    FILEGROWTH = 5 )

    LOG ON

    ( NAME = "DBNAME_LOG",

    FILENAME = "g:",

    SIZE = 5MB,

    FILEGROWTH = 5MB )

    GO

    3.恢復資料庫:

    RESTORE DATABASE DB_SUSPECT

    FROM DBNAME_BACKUP.DAT

    4.資料庫完整性檢測:

    DBCC CHECKDB("DB_SUSPECT")

    5.重新啟動MSSQLSERVER服務.

    如果沒有全備份,那就要用一些特殊的方法:

    1.設定資料庫為緊急模式

    Use Master

    GO

    sp_configure "allow updates", 1

    reconfigure with override

    GO

    UPDATE sysdatabases SET status = 32768 where name = "DB_SUSPECT"

    GO

    2.停掉SQL Server服務:

    .Net STOP MSSQLSERVER

    3.把原始資料庫的資料檔案DBNAME_DAT.MDF,DBNAME_LOG.LDF移走:

    4.啟動SQL Server服務:

    .Net START MSSQLSERVER

    5.重新建立一個同名的資料庫DB_SUSPECT;

    USE master

    GO

    CREATE DATABASE DB_SUSPECT

    ON

    ( NAME = DBNAME_DAT,

    FILENAME = "C:",

    SIZE = 10,

    FILEGROWTH = 5 )

    LOG ON

    ( NAME = "DBNAME_LOG",

    FILENAME = "g:",

    SIZE = 5MB,

    FILEGROWTH = 5MB )

    GO

    6.設定資料庫執行在單使用者的模式:

    USE MASTER

    GO

    ALTER DATABASE DB_SUSPECT SET SINGLE_USER

    GO

    7.停掉SQL服務:

    .Net STOP MSSQLSERVER

    8.把原來的資料檔案再覆蓋回來:

    9.啟動SQL Server服務:

    .Net START MSSQLSERVER

    10.重新設定SQLSERVER的狀態:

    USE MASTER

    GO

    EXEC sp_resetstatus "DB_SUSPECT"

    11.資料庫完整性檢測:

    DBCC CHECKDB("DB_SUSPECT")

    12.恢復資料庫為多使用者模式:

    USE MASTER

    GO

    ALTER DATABASE DB_SUSPECT SET MULTI_USER

    GO

    13.恢復SQLSERVER原始的配置:

    USE MATER

    GO

    UPDATE sysdatabases SET status = 4194320 where name = "DB_SUSPECT"

    GO

    14.配置SQLSERVER不允許更新系統表:

    USE MASTER

    GO

    sp_configure "allow updates", 0

    reconfigure with override

    GO

    15.重新啟動MSSQLSERVER服務:

    最好重新啟動作業系統

    16.備份資料庫:

    可以透過SQLSERVER企業管理器或T-SQL.需要備份MASTER和DB_SUSPECT

    補充一點,如果用DOMAIN\USER時,要注意對.MDF.LDF的所在目錄的許可權.

    靈驗指令碼

    遇到這種資料庫置疑情況,就執行下面這個指令碼,屢試不爽:

    ======================================================

    --before running any script, run the following to set the

    master database to allow updates

    USE master

    GO

    sp_configure "allow updates", 1

    GO

    RECONFIGURE WITH OVERRIDE

    GO

    --Run the following script

    UPDATE master..sysdatabases SET status = status ^ 256

    WHERE name = "Database_Name"

    --Run the following script

    exec SP_resetstatus Database_Name

    --stop and start the MSDTC at this stage

    --After the procedure is created, immediately disable

    updates to the system tables:

    exec sp_configure "allow updates", 0

    GO

    RECONFIGURE WITH OVERRIDE

    GO

  • 中秋節和大豐收的關聯?
  • 金屬鐵冶煉的條件?