doulin6761 2016-03-03 09:29
浏览 146

使用CodeCeption(PHP)还原数据库会使数据库处于“恢复”状态

I'm trying to restore a MSSQL database at the start of a run of acceptance tests written using CodeCeption (PHP). For those who know CodeCeption, I'm using the dump file to run the restore.

The restore command I'm using works perfectly when run in SQL Management Studio but when run from the test suite, it stays in the "Restoring" state and is therefore not useable. Running

RESTORE DATABASE [dbname] WITH RECOVERY

at this point will fail with the message

"The database cannot be recovered because the log was not restored" however running the full restore command (RESTORE DATABASE [dbname] FROM DISK....)

in Management Studio at this point will work. I'm using WITH REPLACE, RECOVERY on the restore command.

I've also looked at the following blog post (https://blogs.msdn.microsoft.com/brian_swan/2010/07/01/restoring-a-sql-server-database-from-php/) but the solution posted there doesn't appear to work either. I have also tried to run the restore using combinations of xp_cmdshell and sqlcmd but still without success.

I have theorised that the way that CodeCeption runs the dump file, it will already have a connection to the database open so I have added a

USE [master] 

immediately before the restore and checked the processes in activity monitor to ensure that there are no connections to the database being restored.

I'm convinced this is a problem somewhere in the PHP CodeCeption code which can be seen here - https://github.com/Codeception/Codeception/blob/2.1/src/Codeception/Module/Db.php

Any suggestions?

  • 写回答

1条回答 默认 最新

  • dougu8742 2016-03-03 10:57
    关注

    Codeception simply executes SQL statements from SQL file that you configured with dump parameter: https://github.com/Codeception/Codeception/blob/2.1/src/Codeception/Lib/Driver/Db.php#L105

    SqlSrv specific code is in https://github.com/Codeception/Codeception/blob/2.1/src/Codeception/Lib/Driver/SqlSrv.php

    If you know how to improve it, you are welcome to contribute.
    Please add content of your SQL file to the question.
    If it only contains a RESTORE DATABASE statement, then it probably is an issue of pdo_sqlsrv driver.

    My only advice is to use SQL statements CREATE TABLE and INSERT to populate your database.

    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line