使用" GO"在一个事务中 [英] Using "GO" within a transaction

查看:418
本文介绍了使用" GO"在一个事务中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建一个web应用程序,尝试安装/升级上App_Start数据库。 安装过程的一部分是确保数据库安装了asp.net功能。为此,我现在用的是System.Web.Management.SqlServices对象。

I'm building a web app that attempts to install/upgrade the database on App_Start. Part of the installation procedure is to ensure that the database has the asp.net features installed. For this I am using the System.Web.Management.SqlServices object.

我的目的是做一个SQL事务中的所有数据库的工作,如果有任何的失败,回滚事务并使数据库保持不变。

My intention is to do all the database work within an SQL transaction and if any of it fails, roll back the transaction and leave the database untouched.

在SqlServices对象有需要的ConnectionString,但不是一个交易的方法安装。所以不是我用SqlServices.GenerateApplicationServicesScripts像这样:

the SqlServices object has a method "Install" that takes a ConnectionString but not a transaction. So instead I use SqlServices.GenerateApplicationServicesScripts like so:

string script = SqlServices.GenerateApplicationServicesScripts(true, SqlFeatures.All, _connection.Database);
SqlHelper.ExecuteNonQuery(transaction, CommandType.Text, script, ...);

然后我使用的企业库中把SqlHelper。

and then I use the SqlHelper from the Enterprise Library.

但这抛出一个异常,一个对接负荷的错误,也有少数是低于

but this throws an Exception with a butt-load of errors, a few are below

Incorrect syntax near 'GO'.
Incorrect syntax near 'GO'.
Incorrect syntax near 'GO'.
Incorrect syntax near 'GO'.
Incorrect syntax near the keyword 'USE'.
Incorrect syntax near the keyword 'CREATE'.
Incorrect syntax near 'GO'.
The variable name '@cmd' has already been declared. Variable names must be unique within a query batch or stored procedure.

我是presuming它的一些问题与使用中的SQL事务GO语句。

I'm presuming it's some issue with using the GO statement within an SQL Transaction.

我如何能得到这个生成的脚本时以这种方式执行工作。

How can I get this generated script to work when executed in this way.

推荐答案

GO不是SQL关键字。

GO is not a SQL keyword.

这是使用客户端工具(如SSMS)一批分离,打破了整个剧本成批次

It's a batch separator used by client tools (like SSMS) to break the entire script up into batches

您得分手脚本分批自己或使用类似 SQLCMD 与-c GO或OSQL应对GO

You'll have to break up the script into batches yourself or use something like sqlcmd with "-c GO" or osql to deal with "GO"

这篇关于使用" GO"在一个事务中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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