【发布时间】:2015-10-16 14:26:37
【问题描述】:
我有一个数据库版本控制应用程序来更新已部署的数据库。它几乎可以在所有 SQL 语句中顺利运行,但是当我决定使用全文搜索并生成脚本来使用如下语句时,它就坏了。
CREATE FULLTEXT CATALOG [ProductCatalog]
--Create fulltext index on Product
CREATE FULLTEXT INDEX ON [tblProduct] KEY INDEX [PK_Catalog]
ON ([ProductCatalog]) WITH (CHANGE_TRACKING AUTO)
ALTER FULLTEXT INDEX ON [tblProduct] ADD ([ProductName] LANGUAGE [English])
ALTER FULLTEXT INDEX ON [tblProduct] ENABLE
我使用以下代码在 C# SqlTransaction 中执行 SQL 文件
SqlConnection cnn = new SqlConnection("cstring");
SqlTransaction trn = cnn.BeginTransaction();
cnn.Open();
using (SqlCommand cmd = cnn.CreateCommand())
{
cmd.Connection = cnn;
cmd.Transaction = trn;
cmd.CommandText = SQLScript;
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
trn.Commit();
cnn.Close();
如何在没有事务的情况下运行我的脚本?
【问题讨论】:
-
如果我清楚地了解您的尝试,请评论此行:cmd.Transaction = trn;
-
@Keith 很抱歉在编辑问题时输入错误
标签: c# sql-server tsql transactions full-text-search