"GO" is a SQL-Server-Management-Studio specific command and not part of T-SQL.
If you would want to use SQL-scripts with "GO"-commands please refer to this:
c# - Execute a large SQL script (with GO commands) - Stack Overflow[
^]
Otherwise you would have to execute these statements separately (and I suggest using
using
-statements for Sql****-objects):
using (var connection = new SqlConnection("your connection string here"))
{
connection.Open();
using (var command = connection.CreateCommand())
{
command.CommandText = "CREATE DATABASE dbTest;";
command.ExecuteNonQuery();
command.CommandText = "USE dbTest;";
command.ExecuteNonQuery();
}
}
The connection string should best not be hardcoded at the indicated position but be read from a configuration file.
Note that the "USE"-command will affect only the following commands on the same connection, so in this example it's pretty useless.