I am trying to read a large script, thus far I have tried two options:
Option 1:
We can't open large script files in SQL management studio because of the issue of out of memory space, so Initially I used sqlcmd
to execute 160 mb SQL script file on remote host, after 55 minutes some rows were effected with this error, TCP Provider: An existing connection was forcibly closed by the remote host. , communication link failure.
Option 2:
Now I am trying using this example, the file size is 160 MB with lot of insert statements, but Visual Studio crashes
Code:
public ActionResult Index()
{
string scriptDirectory = "e:\\";
string sqlConnectionString = "Integrated Security=SSPI;" +
"Persist Security Info=True;Initial Catalog=TestDB;Data Source=localhost\\SQLEXPRESS";
DirectoryInfo di = new DirectoryInfo(scriptDirectory);
FileInfo[] rgFiles = di.GetFiles("*.sql");
foreach (FileInfo fi in rgFiles)
{
FileInfo fileInfo = new FileInfo(fi.FullName);
string script = fileInfo.OpenText().ReadToEnd(); // here visual studio crashes
SqlConnection connection = new SqlConnection(sqlConnectionString);
Server server = new Server(new ServerConnection(connection));
server.ConnectionContext.ExecuteNonQuery(script);
}
return View();
}
Screen Shot: