これは私の更新された質問です..
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!!");
}
なぜこれが起こるのか誰でも指摘できますか?グーグルで見つけたほとんどすべてのことを試しましたが、期待したものを得ることができませんでした..
c:\windows\assembly 内で "microsoft.sqlserver.batchparser.dll" のバージョンが 10.0.0.0 であることがわかり、c# アプリケーションがバージョン 9.0.242.0 を検索するため、app.config にバインディング リダイレクトを追加することも試みました。これも機能していないようです。私が使用したコードは次のとおりです。
<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>
どんな助けでも本当に感謝しています..