نوشته شده توسط
farzane-
سلام دوستان. یک دیتابیس دارم با کلی دیتا. اسکریپت این دیتابیس رو گرفتم . راهی هست که در سی شارپ ، این دیتابیس در اجرای بار اول برنامه بطور خودکار نصب بشه؟
از اتصال کانکشن استرینگ مطمئن باشید بعدش میتونید کدهارو اجرا کنید
public static string path = "script.sql";
//Read Script
private static string GetScript()
{
var file = new FileInfo(path);
string script = file.OpenText().ReadToEnd();
return script;
}
public static void ExecuteScript()
{
if (File.Exists(path))
{
string script = GetScript();
var splitter = new[] { "\r\nGO\r\n" };
string[] commandTexts = script.Split(splitter,
StringSplitOptions.RemoveEmptyEntries);
foreach (string commandText in commandTexts)
{
using (var ctx = new ClassSRMDataContext(Config.connection))
{
if (!string.IsNullOrEmpty(commandText))
{
ctx.ExecuteCommand(commandText);
}
}
}
}
}