【发布时间】:2013-08-19 08:30:40
【问题描述】:
这是我更新的问题..
当我尝试使用 c# 在数据库中执行一些 sql 文件时,我收到如下所示的错误:
我的 c# 代码是这样的:
if (comboBox1.SelectedItem.ToString() == "master" && comboBox2.SelectedItem.ToString() == "master.sql")
{
oConnection.Open();
Server server = new Server(new ServerConnection(oConnection));
if (MessageBox.Show("Execute " + comboBox2.SelectedItem.ToString() + " in the database " + comboBox1.SelectedItem.ToString() + " ?", "Execute?", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
var output = server.ConnectionContext.ExecuteNonQuery(@"D:\Testpgm\master.sql");
if (!output.Equals(0))
{
try
{
MessageBox.Show(comboBox2.SelectedItem.ToString() + " executed successfully in " + comboBox1.SelectedItem.ToString() + " database");
}
catch (Exception exc)
{
MessageBox.Show("Script Execution Failed,"+exc);
}
}
}
else
{
MessageBox.Show("Execution cancelled by the user");
}
else
{
MessageBox.Show("Either the database or the sql script file selected is wrong!!");
}
谁能指出为什么会发生这种情况?我已经尝试了几乎所有我在谷歌搜索时发现的东西,但不幸的是得到了我所期望的......
我还尝试将绑定重定向添加到我的 app.config,因为我可以在 c:\windows\assembly 中找到“microsoft.sqlserver.batchparser.dll”版本为 10.0.0.0,而我的 c# 应用程序查找版本 9.0 .242.0,这似乎又不起作用。我使用的代码是:
<runtime>
<assemblyBinding xmlns="urn:schemas=microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="microsoft.sqlserver.batchparser" publicKeyToken="89845dcd8080cc91" culture="neutral"/>
<bindingRedirect oldVersion="9.0.242.0" newVersion="10.0.0.0"/>
<publisherPolicy apply="no"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
任何帮助将不胜感激..
【问题讨论】:
-
看起来您的参考资料丢失了 (
Microsoft.SqlServer.BatchParser) -
顺便说一句,您的第一个
if缺少右括号。 -
@AviTurner:之前也检查过..现在,我再次检查..但这对我没有用..
-
@Trickery: 不这么认为......如果你是对的那么它应该会抛出一些语法错误,我猜......而且我在那里找不到任何错误。
-
@VysakhVenugopal 好吧,那么您复制的代码错误。您有两个
else语句一个接一个。