You can't use
GO
in a
SqlCommand
; it's a batch separator which is only recognized by SQL Server Management Studio and associated command-line tools. With ADO.NET, you just issue each batch as a separate command.
The command you're trying to execute doesn't return any records. Therefore,
ExecuteReader
is the wrong method to use. Try
ExecuteNonQuery
instead.
And finally, if you just want to change the current database for a
SqlConnection
, try
the ChangeDatabase
method[
^]:
using (SqlConnection connection = new SqlConnection("YOUR CONNECTION STRING HERE"))
{
connection.Open();
connection.ChangeDatabase(DatabaseNameString);
...
}