Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Updating table structures on distributed Apps
Message
From
14/01/2012 12:42:48
 
 
To
14/01/2012 11:43:22
General information
Forum:
ASP.NET
Category:
Databases
Environment versions
Environment:
C# 4.0
Miscellaneous
Thread ID:
01532901
Message ID:
01532942
Views:
34
Charles
Thanks a lot
It's similar to the code that Namoi pointed me to, but it's been re-filched!
I can see some real goodies in SMO.
It's like a lot of other good things which you don't know exist until you find a need for them.







>>This is filched directly from an answer on Stackoverflow which I have used

http://stackoverflow.com/questions/650098/how-to-execute-an-sql-script-file-using-c-sharp



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";

FileInfo file = new FileInfo(@"E:\Project Docs\MX462-PD\MX756_ModMappings1.sql");

string script = file.OpenText().ReadToEnd();

SqlConnection conn = new SqlConnection(sqlConnectionString);

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

server.ConnectionContext.ExecuteNonQuery(script);
file.OpenText().Close();

}
}
Anyone who does not go overboard- deserves to.
Malcolm Forbes, Sr.
Previous
Reply
Map
View

Click here to load this message in the networking platform