转:http://blog.sqlauthority.com/2007/07/21/sql-server-fix-error-msg-1813-level-16-state-2-line-1-could-not-open-new-database-yourdatabasename-create-database-is-aborted/

SQL SERVER – Fix : Error Msg 1813, Level 16, State 2, Line 1 Could not open new database ‘yourdatabasename’. CREATE DATABASE is aborted.

Fix : Error Msg 1813, Level 16, State 2, Line 1
Could not open new database ‘yourdatabasename’. CREATE DATABASE is aborted.

This errors happens when corrupt database log are attempted to attach to new server. Solution of this error is little long and it involves restart of the server. I recommend following all the steps below in order without skipping any of them.

Fix/Solution/Workaround:

SQL Server logs are corrupted and they need to be rebuilt to make the database operational.
Follow all the steps in order. Replace the yourdatabasename name with real name of your database.
1. Create a new database with same name which you are trying to recover or restore. (In our error message it is yourdatabasename). Make sure the name of the MDF file (primary data file) and LDF files (Log files) same as previous database data and log file.

2. Stop SQL Server. Move original MDF file from older server (or location) to new server (or location) by replacing just created MDF file. Delete the LDF file of new server just created.

3. Start SQL Server. Database will be marked as suspect, which is expected.

4. Make sure system tables of Master database allows to update the values.
USE MASTER
GO
sp_CONFIGURE 'allow updates', 1
RECONFIGURE WITH OVERRIDE
GO

5. Change database mode to emergency mode.
–Following statement will return the current status of the database
SELECT *
FROM sysdatabases
WHERE name = 'yourdatabasename'

—-Following statement will update only one row in database
BEGIN
UPDATE
sysdatabases
SET status = 32768
WHERE name = 'yourdatabasename'
COMMIT TRAN

6. Restart SQL Server (This is must, if it is not done SQL Server will through an error)

7. Execute this DBCC command in query window of Management Studio, this will create new log file. Keep the name of this file same as LDF file just deleted from new server :
DBCC TRACEON (3604)
DBCC REBUILD_LOG(yourdatabasename,'c:\yourdatabasename_log.ldf')
GO

DBCC accepts two parameters : first parameter is database name and second parameter is physical path of the log file. Make sure the path is physical, if you put logical file name it will return an error.

8. Reset the database status using following command.
sp_RESETSTATUS yourdatabasename
GO

9. Turn off the update to system tables of Master database running following script.
USE MASTER
GO
sp_CONFIGURE 'allow updates',0
RECONFIGURE WITH OVERRIDE
GO

This should be resolve the problem mentioned above. I always check consistence of the database as well as I reset the status of the database to original status.

10. Reset the database status to previous status
–Following statement will update only one row in database
BEGIN
UPDATE
sysdatabases
SET status = (value retrieved IN first query OF STEP 5)
WHERE name = 'yourdatabasename‘
COMMIT TRAN
GO'

Note : If during steps 8, 9 , 10 if there is error if database is in use.
Set the database to status single user.
sp_DBOPTION 'yourdatabasename', 'single user','true'
Once the steps 8,9,10 are completed if database is not already in multi user mode run this script.
sp_DBOPTION 'yourdatabasename', 'single user','false'
If there is any issue while doing above process to fix the error let me know. Make sure that you have done all the steps in order and restarted SQL Server where it is mentioned.

Reference : Pinal Dave (http://blog.SQLAuthority.com), BOL (many topics)

posted @ 2011-04-06 18:23 Benny Ng 阅读(34) 评论(0) 编辑

问题:

在使用SQL Server 2000的时候,大家可能已经很习惯用下面的语句在修改系统表了

EXEC sp_configure 'allow updates', 1
RECONFIGURE WITH OVERRIDE;
 
-- do some modification to system tables
 
EXEC sp_configure 'allow updates', 0
RECONFIGURE WITH OVERRIDE;

但是如果在SQL Server 2005中,你还是想通过运行上面的语句来修改系统表,那你就大错特错了,虽然在SQL Server 2005中运行上面的语句是不会有任何报错的,但是但你试图去修改系统表的时候你会得到下面这样的错误信息:

Msg 259, Level 16, State 1, Line 1
Ad hoc updates to system catalogs are not allowed.

这时候你只要在SQL Server 2005的BOL中查一下”allow updates”你就会发现如下的说明:

allow updates Option

Updated: 14 April 2006

This option is still present in the sp_configure stored procedure, although its functionality is unavailable in Microsoft SQL Server 2005 (the setting has no effect). In SQL Server 2005, direct updates to the system tables are not supported.

看来在SQL Server 2005中allow updates只是一个摆设了,根本不能用,而且系统表也不能直接被修改了。但是如果你确实需要修改系统表那怎么办呢?

还好,Microsoft还是没有做绝的,虽然allow updates不能用了,但还是可以通过别的途径修改系统表,那就是:先用单用户模式启动SQL Server 2005实例,然后再用DAC(Dedicated Administrator Connection/专用管理员连接)连接到SQL实例,然后不用运行什么sp_configure就可以直接修改系统表了。

基本的步骤:

1、启动到单用户模式

"C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Binn\sqlservr.exe" -m

2、打开SQL Server Management Studio,在Connect to Server对话框中的Server Name处输入admin:InstanceName,这样就可以用DAC登陆启动的SQL Server实例了。

友情提示:

另外,SQL Server 2005加强了字典管理功能,如果要修改系统表的操作能有存储过程支持的情况下一定要用存储过程,不要去直接修改系统表,以维护数据字典的一致性。

参考资料:

1、allow updates Option

2、Using a Dedicated Administrator Connection

3、Starting SQL Server in Single-User Mode

 

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

 如何使用SQL Server 2005 专用管理员连接(DAC)登录到服务器

 

 什么是DAC
   SQL Server 2005 为管理员提供了一种特殊的诊断连接,以供在无法与服务器建立标准连接时使用。即使在 SQL Server 不响应标准连接请求时,管理员也可以使用这种连接访问 SQL Server,以便执行诊断查询并解决问题。命令行界面 (sqlcmd) 通过使用特殊的管理员开关 (-A),提供并支持这种专用管理员连接 (DAC)
如何使用DAC登录到服务器
1 本机DAC登录 
命令行方式下执行  sqlcmd -A -S sql服务器名
远程DAC登录
  1) 打开远程DAC选项
    '程序'->'Sql Server2005'->  '配置工具'-> 'Sql Server  外围应用配置器'-> '功能的外围应用配置器'-> 'DataBase Engine'->  'DAC' -> '启用远程DAC'
  2)  登录到远程服务器
  sqlcmd -A -S 192.168.0.1 -U sa -P 123456
登录后, 可以通过查询动态管理视图来诊断问题
posted @ 2011-04-06 18:23 Benny Ng 阅读(39) 评论(0) 编辑
 

    由于种种原因,我们如果当时仅仅备份了mdf文件,那么恢复起来就是一件很麻烦的事情了。


    如果您的mdf文件是当前数据库产生的,那么很侥幸,也许你使用sp_attach_db或者sp_attach_single_file_db可以恢复数据库,但是会出现类似下面的提示信息
    设备激活错误。

    物理文件名 'C:\Program Files\Microsoft SQL Server\MSSQL\data\test_Log.LDF' 可能有误。
    已创建名为 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\test_log.LDF' 的新日志文件。

 

    但是,如果您的数据库文件是从其他计算机上复制过来的,那么很不幸,也许上述办法就行不通了。你也许会得到类似下面的错误信息
    服务器: 消息 1813,级别 16,状态 2,行 1
    未能打开新数据库 'test'。CREATE DATABASE 将终止。
    设备激活错误。物理文件名 'd:\test_log.LDF' 可能有误。

 

    怎么办呢?别着急,下面我们举例说明恢复办法。

    A.我们使用默认方式建立一个供恢复使用的数据库(如test)。可以在SQL Server Enterprise Manager里面建立。


    B.停掉数据库服务器。


    C.将刚才生成的数据库的日志文件test_log.ldf删除,用要恢复的数据库mdf文件覆盖刚才生成的数据库数据文件test_data.mdf


    D.启动数据库服务器。此时会看到数据库test的状态为“置疑”。这时候不能对此数据库进行任何操作。

 

    E.设置数据库允许直接操作系统表。此操作可以在SQL Server Enterprise Manager里面选择数据库服务器,按右键,选择“属性”,在“服务器设置”页面中将“允许对系统目录直接修改”一项选中。也可以使用如下语句来实现。
    use master
    go
    sp_configure 'allow updates',1
    go
    reconfigure with override
    go


    F.设置test为紧急修复模式
    update sysdatabases set status=-32768 where dbid=DB_ID('test')
    此时可以在SQL Server Enterprise Manager里面看到该数据库处于“只读\置疑\脱机\紧急模式”可以看到数据库里面的表,但是仅仅有系统表

 


    G.下面执行真正的恢复操作,重建数据库日志文件
    dbcc rebuild_log('test','C:\Program Files\Microsoft SQL Server\MSSQL\Data\test_log.ldf')
    执行过程中,如果遇到下列提示信息:
    服务器: 消息 5030,级别 16,状态 1,行 1
    未能排它地锁定数据库以执行该操作。
    DBCC 执行完毕。如果 DBCC 输出了错误信息,请与系统管理员联系。
    说明您的其他程序正在使用该数据库,如果刚才您在F步骤中使用SQL Server Enterprise Manager打开了test库的系统表,那么退出SQL Server Enterprise Manager就可以了。
    正确执行完成的提示应该类似于:
    警告: 数据库 'test' 的日志已重建。已失去事务的一致性。

    应运行 DBCC CHECKDB 以验证物理一致性。

    将必须重置数据库选项,并且可能需要删除多余的日志文件。

    数据恢复 sql数据库修复 密码恢复

    sql数据库恢复 硬盘异响 坏道修复 文件恢复

    sql server修复 文件修复

    raid数据恢复 sql数据库修复

    raid磁盘阵列 sql恢复 sql server恢复

    硬盘数据恢复 硬盘坏道修复 硬盘数据修复 数据修复
    DBCC 执行完毕。如果 DBCC 输出了错误信息,请与系统管理员联系。

    此时打开在SQL Server Enterprise Manager里面会看到数据库的状态为“只供DBO使用”。此时可以访问数据库里面的用户表了。


    H.验证数据库一致性(可省略)
    dbcc checkdb('test')
    一般执行结果如下:
    CHECKDB 发现了 0 个分配错误和 0 个一致性错误(在数据库 'test' 中)
    DBCC 执行完毕。如果 DBCC 输出了错误信息,请与系统管理员联系。

 

    I.设置数据库为正常状态
    sp_dboption 'test','dbo use only','false'
    如果没有出错,那么恭喜,现在就可以正常的使用恢复后的数据库啦。

 

    J.最后一步,我们要将步骤E中设置的“允许对系统目录直接修改”一项恢复。因为平时直接操作系统表是一件比较危险的事情。当然,我们可以在SQL Server Enterprise Manager里面恢复,也可以使用如下语句完成
    sp_configure 'allow updates',0
    go
    reconfigure with override
    go

posted @ 2011-04-06 18:21 Benny Ng 阅读(17) 评论(0) 编辑

转:http://blog.sina.com.cn/s/blog_4054cfa30100o6ls.html 

在win7的操作系统下安装Oracle11R2

  (2010-11-09 17:49:00)
标签: 

it

在win7的操作系统下安装Oracle11R2

在win7的操作环境中大部分的Oracle安装都显得那么的困难,这段时间我也在学Oracle,下了Oracle9却无法安装就去,查了一天的资料,只好去下64位的Oracle11R2,大家可以到http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/winsoft.html去下载如下的两个压缩的文件(win64_11gR2_database_1of2.zip和win64_11gR2_database_2of2.zip),注意这连个文件一定要解压到同一个文件里面,不要分解窑到连个文件夹里面,不让在安装的时候就会出错先先前的错误:

racle11g for windows2008 安装错误:未找到文件WFMLRSVCApp.ear
将win64_11gR2_database_1of2.zip和win64_11gR2_database_2of2.zip分别解压后,
点开始安装,过程很顺利,到54%时杯具出现了:未找到文件 c:oracle....WFMLRSVCApp.ear。
查看install guide找不到解决方法,最后,把两个文件解压到同一个目录下面,再安装,终于顺利完成了。

在解压的时候你会发现解药的文件有许多后缀名为(jad)的文件,那就是预告你这个安装程序是基于Java的,意思就是要安装Java的jdk(jdk-6u18-windows-i586_java_SE.exe)Java SE,可以到http://java.com/zh_CN/下载安装后,我门就可以安装oracle了,双击setup.exe就可以一路安装下去了

 

下载一个PL/SQL  Developer8.04下来进行安装,按住后但是无法使用,查了一天的资料总算找到了结果;

1、要想使用PL/SQL需要先安装oracle客户端(这个是必须的,要不然plsql就用不了,

这个客户端可以去oracle官网上下载,名字叫instance client(全名instantclient-basic-win32-11.2.0.1.0,我安装的oracle 11是64为的,但是PL/SQL  Developer8.04是32 位的,那就是要下载一个32 位的instance client),尽量用较新的版本就可以了

,windows版的大的也就50多M,还有精简版的20多M,

地址:http://www.oracle.com/technology/global/cn/software/tech/oci/instantclient/index.html

挑个适合你的系统的版本的。)

oracle客户端的安装很简单,直接解压出来,放到你oracle所安装的x:\app\Administrator\product目录下,我的oracle是按在F盘,所以我就解压到F:\app\Administrator\product目录下如图:

在win7的操作系统下安装Oracle11R2

 

(被选择的就是解压出来,被我去掉了最顶层文件的文件夹所以名字有点不一样)

在oracle的安装路径F:\app\Administrator\product\11.2.0\dbhome_1\NETWORK\ADMIN的文件夹里找到tnsnames.ora,并拷贝到文件到InstantClient解压目录F:\app\Administrator\product\instantclient_11_2下,这一下就算大功完成了一般哟,呵呵呵呵

接下来就是配置PL/SQL  Developer8.04:

在非登录状态下进入PL/SQL developer,进入首选项,在connection中设置Oracle_Home和OCI Library,其中

Oracle_Home设置为InstantClient的解压目录,OCI Library设置为该目录下的oci.dll.如图:

在win7的操作系统下安装Oracle11R2


 

单击确定。

 

接下来到win7的桌面上右键单击我的电脑-》属性》高级系统设置》环境变量

在Administration的用户变量中新建如下的环境变量:

添加的变量                                 变量的值

NLS_LANG              AMERICAN_AMERICA.ZHS16GBK

ORACLE_HOME       F:\app\Administrator\product\instantclient_11_2

path                             F:\app\Administrator\product\instantclient_11_2

TNS_ADMIN             F:\app\Administrator\product\instantclient_11_2

单击确定后就可以启动PL/SQL developer,输入密码就可以进入了。

 

用一段时间后你会发现在oracle应用程序自带的sqlplus无法启动如下图,如果你不用PL/SQL developer,要用sqlplus,直接报上面建立的环境变量都删除掉就行了,但是就无法应用了。

posted @ 2011-04-06 10:08 Benny Ng 阅读(97) 评论(0) 编辑