SQL Server Express 2008 不分离自动附加文件? [英] SQL Server Express 2008 not detaching auto-attached file?

查看:23
本文介绍了SQL Server Express 2008 不分离自动附加文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQLEXPRESS 的 MSDN 文档 说:

The MSDN documentation for SQLEXPRESS says:

当应用程序首次与正在运行的 SQL Server Express 实例建立连接时,SQL Server Express 将自动附加一个 .mdf 文件.当用户关闭应用程序时,SQL Server Express 会从实例中分离 .mdf 文件.

When an application first establishes a connection from a running instance of SQL Server Express, SQL Server Express will automatically attach an .mdf file. When the user closes the application, SQL Server Express detaches the .mdf file from the instance.

这似乎没有发生.如果我用一个新的同名文件替换 MDF 文件(当然是在删除日志文件之后),SQL Server Express 将拒绝附加它.

This does not appear to be happening. If I replace the MDF file with a new one of the same name (after deleting the log file, of course) SQL Server Express will refuse to attach it.

我已经尝试了几乎所有可能的连接字符串参数组合,这让我很抓狂.有什么建议吗?

I've tried just about every combination of connection string parameters possible, and it's driving me crazy. Any suggestions?

推荐答案

分离/关闭确实发生了.如果它不会发生,那么您就不可能替换 MDF 文件,因为它将被使用.您引用的文档并不完全准确.正确的文档位于 SQL Server 2005 Express Edition User实例:

The detach/close does happen. If it wouldn't happen then you could not possibly replace the MDF file, because it would be in use. The documentation you quote is not entirely accurate. The correct documentation is at SQL Server 2005 Express Edition User Instances:

  • 用户实例数据库具有自动关闭选项集,以便如果有8-10 岁没有与数据库的连接分钟,数据库关闭并文件已关闭.有时候是这样的自动,但它可能需要一个同时,特别是如果连接池已为您启用连接.
  • 分离数据库通过调用从实例sp_detach_db 将关闭文件.这个是 Visual Studio 使用的方法确保数据库文件是当 IDE 之间切换时关闭用户实例.
  • User instance databases have the Auto Close option set so that if there are no connections to a database for 8-10 minutes, the database shuts down and the file is closed. This happens automatically, but it can take a while, especially if connection pooling is enabled for your connections.
  • Detaching the database from the instance by calling sp_detach_db will close the file. This is the method Visual Studio uses to ensure that the database file is closed when the IDE switches between user instances.

如果我敢猜测,我会说数据库不是分离的而是自动关闭的,并且在尝试打开数据库时,删除 LDF 后重新安装 MDF 将(理所当然地)被视为错误.

If I'd venture a guess I'd say that the database is not detached but auto-closed, and replcing the MDF after deleting the LDF will be (rightfully) seen as an error when trying to open the database.

附注:

  • 永远不要删除 LDF 文件.如果要替换数据库,请将两者 MDF 和 LDF 替换为新的.
  • 确保更换为合适的 MDF 和 LDF 版本.SQL Server 可以升级数据库,但永远不能将其降级.
  • 获取错误信息.如果 SQL Express 拒绝附加数据库,它会给出一个原因.查看 RANU 创建的 ERRORLOG(在用户配置文件中)、系统事件日志,或将分析器附加到用户实例.
  • One should never ever delete the LDF file. If you want to replce the database, replace both the MDF and the LDF with the new ones.
  • Make sure you replace with proper MDF and LDF versions. SQL Server can upgrade a database, but can never downgrade it.
  • Get the error. If SQL Express refuses to attach a database, it will give a reason. Look into the RANU created ERRORLOG (in the user profile), the systen event log, or attach profiler to the user instance.

这篇关于SQL Server Express 2008 不分离自动附加文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆