SORU
16 Mart 2009, PAZARTESİ


Çalıştırmak için nasıl bir .SQL komut dosyası kullanarak c#

Bu soruya zaten cevap olmuştur eminim, ancak bir cevap arama aracını kullanarak bulamadı.

C# ı kullanarak çalıştırmak istiyorum .dosya sql. Sql dosyası içinde birden fazla satır kırık, bazıları birden fazla sql ifadeleri içerir. Dosya okumaya çalıştım ve dosya odp.net ... ancak Programının gerçekten bunu yapmak için tasarlanmış olduğunu sanmıyorum, yürütmesi çalıştı.

Bir süreç yumurtlama ile sqlplus kullanarak denedim ... ancak UseShellExecute doğru sqlplus için ayarlama işlemi kökenli sürece asmak ve hiç çıkmak istiyorsunuz. Burada İŞE yaramaz bu kodu.

Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "sqlplus";
p.StartInfo.Arguments = string.Format("xx/xx@{0} @{1}", in_database, s);
p.StartInfo.CreateNoWindow = true;

bool started = p.Start();
p.WaitForExit();

WaitForExit asla...döner. UseShellExecute gerçek kurdum tabii. UseShellExecute bir yan etkisi yönlendirilen çıkış yakalayabilir hayır.

CEVAP
13 Kasım 2009, Cuma


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;
using System.IO;
using System.Data.SqlClient;

public partial class ExcuteScript : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    string sqlConnectionString = @"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=ccwebgrity;Data Source=SURAJIT\SQLEXPRESS";

    string script = File.ReadAllText(@"E:\Project Docs\MX462-PD\MX756_ModMappings1.sql");

    SqlConnection conn = new SqlConnection(sqlConnectionString);

    Server server = new Server(new ServerConnection(conn));

    server.ConnectionContext.ExecuteNonQuery(script);
    }
}

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • jeffisthecoolguy

    jeffisthecoo

    17 HAZİRAN 2013
  • MovieZoneET

    MovieZoneET

    22 Aralık 2009
  • WestsideMrArO

    WestsideMrAr

    6 EKİM 2010