Celebrating 8 Successful Years
+1 (315)-715-8489

Executing Sql Scripts with Go Statements as CommandText

Here is the code lines for executing the sql script . we may get the errors while executing any string as CommandText that loaded with sql script. This causes due to the GO Statements. I'm providing these code lines to split that Go statements. Hope this is helpful to execute script file with Go Statements.

                 string sqlBatch = string.Empty;
                    script += "\nGO";
                    SqlCommand cmd = new SqlCommand("", conn);
                    foreach (string line in script.Split(new string[2] { "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries))
                        if (line.ToUpperInvariant().Trim() == "GO")
                            cmd.CommandText = sqlBatch;
                            sqlBatch = string.Empty;
                            sqlBatch += line + "\n";

Sai Venkat - Software Developer

Get In Touch


© Copyright 2016 by SKG Infosolution. All rights reserved