使用 Web 部署 (msdeploy) 发布 WebMatrix 站点
我开始在 WebMatrix 中构建我的网站,然后转而使用 VS2010,这样我可以获得更好的智能感知和调试。我一直在加载 WebMatrix 进行部署,并且运行良好。
然而,加载 WebMatrix 是一个 PITA,我实际上希望 Web 部署过程具有更大的灵活性。
所以我开始学习 msdeploy.exe 以及如何使用它。我能够使用以下命令行成功地使站点按照我想要的方式同步:
msdeploy.exe
-verb:sync
-dest:iisApp=MySite,wmsvc=www.mysite.com,username=administrator,password=blahblahblah
-allowUntrusted
-skip:absolutePath=webdeploy.cmd
-skip:absolutePath=web.config
-skip:objectName=dirPath,absolutePath="App_Data"
-skip:objectName=dirPath,absolutePath="bin"
-skip:absolutePath=vwd.webinfo
-source:iisApp="C:\Users\charlie\Documents\Visual Studio 2010\WebSites\MySite"
我必须使用 -allowTrusted
因为服务器上的证书使用与 www 不同的主机名。没什么大不了的。我也有一些 -skips
来处理我不想写入目标的内容。
一切都很好。
我在我的主机(AWS 上的 WebMatrix AMI)上使用 SQL Server (Express)。
我也希望能够将我的数据库推送到主机。我正在尝试使用以下 msdeploy 命令:
msdeploy.exe
-verb:sync
-source:dbFullSql="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=C:....\MySite.mdf;User instance=true"
-dest:dbFullSql="Server=www.mysite.com\SQLEXPRESS;Initial Catalog=webmatrix_db;Uid=webmatrix_user;Pwd=<pwd>"
这让我
Error: The database 'webmatrix_db' could not be created.
Error: A network-related or instance-specific error occurred while establishing aa
connection to SQL Server. The server was not found or was not accessible. ...
认为我的问题是连接字符串。我从 WebMatrix UI 复制了 Server=".\SQLEXPRESS;Initial Catalog=webmatrix_db;Uid=webmatrix_user;Pwd=
并在其前面加上 www.mysite.com< /code> 认为它需要我的主机名。
显然这是不正确的,而且我也找不到任何可用的连接字符串示例。
请注意,我认为该服务器不会直接公开 SQL。 WebMatrix 对 msdeploy 的调用首先使用我的管理员凭据(而不是 SQL 凭据)进行连接,然后 msdeploy 调用远程主机上的 SQL 命令,我需要类似 ...wmsvc=www.mysite.com,username= 的内容。 admin,password=blahblahblah
在我上面给出的第一个示例的 -dest
选项中,
如果我能看到 WebMatrix 的日志,那就太棒了 。调用 msdeploy 来执行
我想要的操作的正确 msdeploy 命令是什么?
[更新 - 答案]
StackOverflow 最好的事情之一是,发布问题确实能让您思考自己在做什么。在我发布上述内容后不久,我意识到 -dest
参数中的 wmsvc=www.mysite.com,username=administrator,password=blahblahblah
参数是关键。问题变成了如何将其正确添加到我的具体示例中。
此 msdeploy 命令行现在可以正确连接:
msdeploy.exe -verb:sync -source:dbFullSql="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=C:\Users\charlie\Documents\Visual Studio 2010 \WebSites\Fiinom\App_Data\MySite.mdf;用户实例=true" -dest:dbFullSql="Server=.\SQLEXPRESS;Initial Catalog=webmatrix_db;Uid=webmatrix_user; Pwd=rI2vP3rK6hV8nN8",wmsvc=www.mysite.com,username=administrator,password=blahblahblah -allowUntrusted
现在 msdeploy正在成功连接并执行命令,我需要弄清楚如何真正实现它合并数据库。现在它给我一个错误,表已经存在并且无法创建它......
I started building my site in WebMatrix and then switched to using VS2010 so I could have better Intellisense and debugging. I've been loading WebMatrix to deploy and it's been working fine.
However, loading WebMatrix is a PITA and I actually want more flexibility over the web deployment process.
So I started learning about msdeploy.exe and how to use it. I was able to successfully get the site to sync as I wanted with the following command line:
msdeploy.exe
-verb:sync
-dest:iisApp=MySite,wmsvc=www.mysite.com,username=administrator,password=blahblahblah
-allowUntrusted
-skip:absolutePath=webdeploy.cmd
-skip:absolutePath=web.config
-skip:objectName=dirPath,absolutePath="App_Data"
-skip:objectName=dirPath,absolutePath="bin"
-skip:absolutePath=vwd.webinfo
-source:iisApp="C:\Users\charlie\Documents\Visual Studio 2010\WebSites\MySite"
I had to use -allowTrusted
because the cert on the server uses a differnt host name than www. No biggie. I have some -skips
for stuff I don't want to write to the dest as well.
It all works great.
I use SQL Server (Express) on my host (a WebMatrix AMI on AWS).
I want to have the ability to push my database to the host as well. I am trying to use the following msdeploy commmand:
msdeploy.exe
-verb:sync
-source:dbFullSql="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=C:....\MySite.mdf;User instance=true"
-dest:dbFullSql="Server=www.mysite.com\SQLEXPRESS;Initial Catalog=webmatrix_db;Uid=webmatrix_user;Pwd=<pwd>"
This gives me
Error: The database 'webmatrix_db' could not be created.
Error: A network-related or instance-specific error occurred while establishing aa
connection to SQL Server. The server was not found or was not accessible. ...
I think my problem is the connection string. I copied Server=".\SQLEXPRESS;Initial Catalog=webmatrix_db;Uid=webmatrix_user;Pwd=<pwd>
from the WebMatrix UI and pre-pended it with www.mysite.com
thinking it needed my hostname somewhere.
Obviously this is not correct and I can't find any examples of connection strings that work either.
Note that SQL is not exposed directly by this server. I assume WebMatrix's invocation of msdeploy is connecting using my admin credentials (not the SQL credentials) first and then msdeploy invokes the SQL commands on the remote host. I need something like the ...wmsvc=www.mysite.com,username=administrator,password=blahblahblah
in the -dest
option of the first example I gave above.
It would be awesome if I could see a log of how WebMatrix was invoking msdeploy.
What is the correct msdeploy command to do what I want?
[UPDATE - ANSWER]
One of the best things about StackOverflow, is that posting a question really makes you think about what you are doing. Shortly after I posted the above, I realized the wmsvc=www.mysite.com,username=administrator,password=blahblahblah
parameter in the -dest
parameter was the key. The question became how to correctly add it to my specific example.
This msdeploy command line now connects correctly:
msdeploy.exe -verb:sync -source:dbFullSql="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=C:\Users\charlie\Documents\Visual Studio 2010\WebSites\Fiinom\App_Data\MySite.mdf;User instance=true" -dest:dbFullSql="Server=.\SQLEXPRESS;Initial Catalog=webmatrix_db;Uid=webmatrix_user; Pwd=rI2vP3rK6hV8nN8",wmsvc=www.mysite.com,username=administrator,password=blahblahblah -allowUntrusted
Now that msdeploy is connecting successfully and executing commands, I need to figure out how to make it actually merge the database. Right now it's giving me an error that a table already exists and can't create it...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这与您对合并数据库的旁注有关...
当前 Web 部署没有任何支持数据库合并的提供程序 - dbFullSql 提供程序使用 SQL Server 管理对象(“SMO”)来编写数据库内容的脚本,然后我们应用它在另一边。因此,有效的 Web 部署只会用源数据库覆盖目标数据库。
如果您同意将其作为“合并”,您可以使用 SMO 脚本选项来解决该表已存在的错误 - 这就是 WebMatrix 为使数据库发布/下载工作所做的工作。只需在您的源中添加:
,scriptDropsFirst=true
(这个脚本会删除源数据库中的所有对象,这样如果它们存在于目标数据库中,它们就会被删除并且不会阻止您)
您可能还需要:
,copyAllUsers=false
(如果您不是远程 SQL 数据库的系统管理员,您很可能无法创建登录名,这是服务器级别的操作。通常,如果您不使用此设置,您会收到错误消息关于创建登录名,或者登录名不存在,因为 SMO 将您的数据库用户脚本编写为“for LOGIN”,并且该登录名在服务器上不存在)
希望有帮助!
克里斯蒂娜
This is related to your side comment on merging the database...
Currently Web Deploy does not have any provider that supports database merges - the dbFullSql provider uses SQL Server Management Objects ("SMO") to script out the db contents and we then apply it on the other side. Effectively Web Deploy thus will only overwrite the destination db with the source db.
If you are okay with that as a "merge" you can get around that table already exists error by using SMO scripting options - this is what WebMatrix does to make the db publishing/downloading work. To your source just add:
,scriptDropsFirst=true
(this scripts out drops for all the objects in your source database so that if they exist on the destination they will get dropped and won't block you)
You might also need:
,copyAllUsers=false
(if you aren't a sysadmin on the remote SQL database, chances are you won't be able to create logins, which are a server-level action. Typically if you don't use this setting, you'll get an error about creating a login, or login doesn't exist, because SMO scripts our your database user as "for LOGIN " and that login doesn't exist on the server)
Hope that helps!
Kristina