无法将northwind数据库附加到sql server 2008 R2

时间:2022-10-12 18:03:43

When I try to I get the following error in SQL Server Management Studio:

当我尝试在SQL Server Management Studio中收到以下错误时:

TITLE: Microsoft SQL Server Management Studio

标题:Microsoft SQL Server Management Studio

Attach database failed for Server 'AHAKEEM'. (Microsoft.SqlServer.Smo)

服务器'AHAKEEM'附加数据库失败。 (Microsoft.SqlServer.Smo)

ADDITIONAL INFORMATION:

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)

执行Transact-SQL语句或批处理时发生异常。 (Microsoft.SqlServer.ConnectionInfo)

Unable to open the physical file "C:\SQL Server 2000 Sample Databases\northwnd.mdf". Operating system error 5: "5(failed to retrieve text for this error. Reason: 15105)". (Microsoft SQL Server, Error: 5120)

无法打开物理文件“C:\ SQL Server 2000示例数据库\ northwnd.mdf”。操作系统错误5:“5(无法检索此错误的文本。原因:15105)”。 (Microsoft SQL Server,错误:5120)

This is a fresh version of Northwinds mdf which just came from Microsoft's installer.

这是Northwinds mdf的新版本,它刚刚来自微软的安装程序。

3 个解决方案

#1


8  

Error 5120 is a sharing violation on the file you're opening. Try starting SQL Management Studio as Administrator and make sure that the db isn't attached already.

错误5120是您正在打开的文件的共享冲突。尝试以管理员身份启动SQL Management Studio,并确保未附加数据库。

#2


0  

The error occurs when the mdf or ldf file is missing, if its an ldf we can recreate the same using the below listed scripts:

当mdf或ldf文件丢失时会发生错误,如果它是ldf,我们可以使用下面列出的脚本重新创建它:

Method 1: To recreate all the log files

方法1:重新创建所有日志文件

EXECUTE sp_attach_single_file_db @dbname = 'SAMPLEDB',
@physname = N'D:\MSSQL\DATA\SAMPLEDB.mdf' 
GO

Method 2: If one or more log files are missing, they are recreated again.

方法2:如果缺少一个或多个日志文件,则会再次重新创建它们。

CREATE DATABASE SAMPLEDB ON
(FILENAME = N'D:\MSSQL\DATA\SAMPLEDB.mdf')
FOR ATTACH_REBUILD_LOG
GO 

Method 3: If only one file is missing, they are recreated again.

方法3:如果只丢失一个文件,则会再次重新创建它们。

CREATE DATABASE SAMPLEDB ON
( FILENAME = N'D:\MSSQL\DATA\SAMPLEDB.mdf')
FOR ATTACH
GO

#3


0  

I tried to install Northwind and pubs Sample Databases for SQL Server 2000 and attach both databases in SQL Server 2014, and gave me an error because they were compatible version.

我尝试为SQL Server 2000安装Northwind和pubs示例数据库并在SQL Server 2014中附加这两个数据库,并且因为它们是兼容版本而给了我一个错误。

These are the steps to successful install the Sample Database in your SQL Server 2014:

以下是在SQL Server 2014中成功安装示例数据库的步骤:

  1. After you download the Sample Databases in your PC, then open SQL Server 2014 Management Studio. After successful connection, your SQL Server instance should be listed in the Object Explorer.
  2. 在PC中下载示例数据库后,打开SQL Server 2014 Management Studio。连接成功后,您的SQL Server实例应列在对象资源管理器中。

  3. Now under File Menu select Open > File. Find the instnwnd.sql in your computer and select it. Click Open SQL script should open in the main window. Do not click on Execute yet. If you do, you will get the following error:
  4. 现在在File Menu下选择Open> File。在计算机中找到instnwnd.sql并选择它。单击打开SQL脚本应在主窗口中打开。不要点击执行。如果这样做,您将收到以下错误:

Could not find stored procedure ‘sp_dboption’.

找不到存储过程'sp_dboption'。

  • Around the line 20, remove the following two lines:
  • 在第20行附近,删除以下两行:

exec sp_dboption 'Northwind','trunc. log on chkpt.','true' exec sp_dboption 'Northwind','select into/bulkcopy','true'

exec sp_dboption'Northwind','trunc。登录chkpt。','true'exec sp_dboption'Northwind','select into / bulkcopy','true'

  • Replace them with this line as shown below:
  • 用这条线替换它们,如下所示:

alter database Northwind set recovery simple

alter database Northwind设置恢复简单

To attach 'pubs' database, repeat the step 2 above and this time open instpubs.sql file. Replace the sp_dboption as you did before with:

要附加'pubs'数据库,请重复上面的步骤2,这次打开instpubs.sql文件。像以前一样替换sp_dboption:

alter database Pubs set recovery simple

alter database Pubs设置恢复简单

  • All that is left is to execute the script, so click on Execute in both scripts.
  • 剩下的就是执行脚本,所以在两个脚本中单击Execute。

Note: the folder location for your sample database by default is "C:\SQL Server 2000 Sample Databases"

注意:默认情况下,示例数据库的文件夹位置为“C:\ SQL Server 2000示例数据库”

#1


8  

Error 5120 is a sharing violation on the file you're opening. Try starting SQL Management Studio as Administrator and make sure that the db isn't attached already.

错误5120是您正在打开的文件的共享冲突。尝试以管理员身份启动SQL Management Studio,并确保未附加数据库。

#2


0  

The error occurs when the mdf or ldf file is missing, if its an ldf we can recreate the same using the below listed scripts:

当mdf或ldf文件丢失时会发生错误,如果它是ldf,我们可以使用下面列出的脚本重新创建它:

Method 1: To recreate all the log files

方法1:重新创建所有日志文件

EXECUTE sp_attach_single_file_db @dbname = 'SAMPLEDB',
@physname = N'D:\MSSQL\DATA\SAMPLEDB.mdf' 
GO

Method 2: If one or more log files are missing, they are recreated again.

方法2:如果缺少一个或多个日志文件,则会再次重新创建它们。

CREATE DATABASE SAMPLEDB ON
(FILENAME = N'D:\MSSQL\DATA\SAMPLEDB.mdf')
FOR ATTACH_REBUILD_LOG
GO 

Method 3: If only one file is missing, they are recreated again.

方法3:如果只丢失一个文件,则会再次重新创建它们。

CREATE DATABASE SAMPLEDB ON
( FILENAME = N'D:\MSSQL\DATA\SAMPLEDB.mdf')
FOR ATTACH
GO

#3


0  

I tried to install Northwind and pubs Sample Databases for SQL Server 2000 and attach both databases in SQL Server 2014, and gave me an error because they were compatible version.

我尝试为SQL Server 2000安装Northwind和pubs示例数据库并在SQL Server 2014中附加这两个数据库,并且因为它们是兼容版本而给了我一个错误。

These are the steps to successful install the Sample Database in your SQL Server 2014:

以下是在SQL Server 2014中成功安装示例数据库的步骤:

  1. After you download the Sample Databases in your PC, then open SQL Server 2014 Management Studio. After successful connection, your SQL Server instance should be listed in the Object Explorer.
  2. 在PC中下载示例数据库后,打开SQL Server 2014 Management Studio。连接成功后,您的SQL Server实例应列在对象资源管理器中。

  3. Now under File Menu select Open > File. Find the instnwnd.sql in your computer and select it. Click Open SQL script should open in the main window. Do not click on Execute yet. If you do, you will get the following error:
  4. 现在在File Menu下选择Open> File。在计算机中找到instnwnd.sql并选择它。单击打开SQL脚本应在主窗口中打开。不要点击执行。如果这样做,您将收到以下错误:

Could not find stored procedure ‘sp_dboption’.

找不到存储过程'sp_dboption'。

  • Around the line 20, remove the following two lines:
  • 在第20行附近,删除以下两行:

exec sp_dboption 'Northwind','trunc. log on chkpt.','true' exec sp_dboption 'Northwind','select into/bulkcopy','true'

exec sp_dboption'Northwind','trunc。登录chkpt。','true'exec sp_dboption'Northwind','select into / bulkcopy','true'

  • Replace them with this line as shown below:
  • 用这条线替换它们,如下所示:

alter database Northwind set recovery simple

alter database Northwind设置恢复简单

To attach 'pubs' database, repeat the step 2 above and this time open instpubs.sql file. Replace the sp_dboption as you did before with:

要附加'pubs'数据库,请重复上面的步骤2,这次打开instpubs.sql文件。像以前一样替换sp_dboption:

alter database Pubs set recovery simple

alter database Pubs设置恢复简单

  • All that is left is to execute the script, so click on Execute in both scripts.
  • 剩下的就是执行脚本,所以在两个脚本中单击Execute。

Note: the folder location for your sample database by default is "C:\SQL Server 2000 Sample Databases"

注意:默认情况下,示例数据库的文件夹位置为“C:\ SQL Server 2000示例数据库”