是什么原因导致“SQL01268: Msg 1834: 无法覆盖。它正在被数据库使用”? (在数据库项目中)
以下完整错误:
<块引用>错误 1 SQL01268:.Net SqlClient 数据提供程序:消息 1834,级别 16,状态 1,第 1 行 文件“C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\testdatabase.mdf”无法被覆盖。它正在被数据库“testdatabase”使用。架构比较5 25 0
我在一些论坛上读到了这一点,很多人都得到了这一点,据说对于某些人来说,它与参数化数据库等的文件路径名有关,或者勾选“忽略文件名和文件和日志文件的路径” “在进行比较之前 - 我已经尝试过但没有成功。
其他有相同/类似问题的人:http://social.msdn.microsoft.com/Forums/en/vstsdb/thread/5a8b8c52-adb4-4a5a-95ed-09ad22bacf60
基本上对我来说,我似乎得到这个错误,无论我使用哪些数据库作为目标和源。假设即使我创建一个包含一个表的新数据库和另一个没有表且名称不同的数据库,并尝试使用带有单个表的数据库来更新没有表的数据库的架构,它仍然会给我错误。几乎就像 SQL Server Express 已经疯了一样。我记得之前使用过模式比较工具,没有遇到任何问题。所有数据库连接都已创建,尝试了很多方法都无济于事,即:指向另一个文件夹中的 *.mdf db 副本或从程序文件中的 mysql 目录中的 DATA 文件夹中删除内容等。
也相信我读到有人已经解决了类似的问题是删除该方案的一些文件 比较工具创建,认为它们是 *.sql 类型,但不确定是哪些。
Full error below:
Error 1 SQL01268: .Net SqlClient Data Provider: Msg 1834, Level 16, State 1, Line 1 The file 'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\testdatabase.mdf' cannot be overwritten. It is being used by database 'testdatabase'. SchemaCompare5 25 0
I read about this on some forums and quite a few people were getting this and supposedly for some it had to do with parameterising the file path name to the db etc. or ticking "ignore file names and path for files and log files" prior to doing the comparison - this I have tried to no avail.
Someone else who has the same/similar issue: http://social.msdn.microsoft.com/Forums/en/vstsdb/thread/5a8b8c52-adb4-4a5a-95ed-09ad22bacf60
Basically for me I seem to get this error irrespective of which databases I am using for target and source. Say even if I create a new database with one table and another database with no tables and different name and try to update the schema of the database with no tables using the db with the single table it still gives me the error. Almost like SQL server express has gone nuts. I remember using the schema comparison tool before with no trouble. All db connections were created, tried many ways to do this to no avail ie: pointing to copy of *.mdf db in another folder or deleting things from the DATA folder in mysql directory in program files etc.
Also believe I read someone had solved a similar issue be deleting some files the scheme
comparison tool creates, think they were *.sql type not sure which ones though.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
出现问题是因为数据库文件已经存在。
在 Visual Studio 数据库项目中尝试以下操作。
创建架构比较。
转到菜单:数据>模式比较>导出到>编辑器
创建脚本后,删除添加物理文件的更改数据库命令。然后创建连接,切换到 SQLCMD 模式(确保您专注于脚本)并执行脚本。
要切换到 SQLCMD 模式访问:Data > Transact-SQL 编辑器 > SQLCMD模式
The problem arises because the database files already exist.
Try the below within the Visual Studio database project.
Create the schema comparison.
Go to menu: Data > Schema Compare > Export to > Editor
Once the script has been created delete the alter database commands that add the physical files. Then create a connection, switch to SQLCMD mode (making sure you have focus on the script) and execute the script.
To switch to SQLCMD mode access: Data > Transact-SQL Editor > SQLCMD Mode
如果目标数据库已经存在,只需在首次部署之前先通过 Management Studio 删除即可。
当我在VS中通过SQL Server 2008向导创建数据库项目时建立原始连接时,我已经通过SQL Server Management Studio手动创建了数据库。在它检测到数据库存在之前,它不允许我继续。然后,当我第一次进入部署步骤时,它抛出了与上面相同的错误。我刚刚进入 Management Studio 并删除了数据库,然后尝试部署并且工作正常。有趣的是,它现在每次都会部署,而我不必每次都进去删除它。
If the target DB already exists, just delete through Management Studio first before you deploy for the first time.
I had already created the database manually through SQL Server Management Studio when I was establishing the original connection when creating the Database Project via the SQL Server 2008 Wizard in VS. It wouldn't allow me to continue until it could detect that the database existed. Then once I got to the Deploy step for the first time, it threw the same error as above. I just went into Management Studio and deleted the DB, then tried to deploy and it worked fine. Interestingly, it's deploying every time now without me having to go in and delete it every time.